开发者

hibernate3-maven-plugin: entiries in different maven projects, hbm2ddl fails

I'm trying to put an entity in a different maven project. In the current project I have:

@Entity
public class User {
...
private FacebookUser facebookUser;
...
public FacebookUser getFacebookUser() {
    return facebookUser;
}
...
public void setFacebookUser(FacebookUser facebookUser) {
    this.facebookUser = facebookUser;
}

Then FacebookUser (in a different maven project, that's a dependency of a current project) is defined as:

@Entity
public class FacebookUser {
...
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
public Long getId() {
    return id;
}

Here is my maven hibernate3-maven-plugin configuration:

        <plugin>
           <groupId>org.codehaus.mojo</groupId>
           <artifactId>hibernate3-maven-pl开发者_运维知识库ugin</artifactId>
           <version>2.2</version>
           <executions>
             <execution>
               <phase>process-classes</phase>
               <goals>
                 <goal>hbm2ddl</goal>
               </goals>
             </execution>
           </executions>
           <configuration>
             <components>
               <component>
                 <name>hbm2ddl</name>
                 <implementation>jpaconfiguration</implementation>
               </component>
             </components>
             <componentProperties>
               <ejb3>false</ejb3>
               <persistenceunit>Default</persistenceunit>
               <outputfilename>schema.ddl</outputfilename>
               <drop>false</drop>
               <create>true</create>
               <export>false</export>
               <format>true</format>
             </componentProperties>
           </configuration>
        </plugin>

Here is the error I'm getting:

org.hibernate.MappingException: Could not determine type for: com.xxx.facebook.model.FacebookUser, at table: user, for columns: [org.hibernate.mapping.Column(facebook_user)]

I know that FacebookUser is on the classpath because if I make facebook user transient, project compiles fine:

@Transient
public FacebookUser getFacebookUser() {
    return facebookUser;
}  


A FacebookUser is not a basic type and can't be persisted in a column of the User table, it's a real entity that is actually persisted in another table. What you have here is a one-to-one relation between User and FacebookUser and you need to declare it as such:

@OneToOne
public FacebookUser getFacebookUser() {
    return facebookUser;
} 


You might want to try adding the dependencies as 'test' and not just compile. From http://mojo.codehaus.org/maven-hibernate3/hibernate3-maven-plugin/hbm2ddl-mojo.html:

Requires dependency resolution of artifacts in scope: test

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜