views:

217

answers:

2

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-plugin</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: 

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;
} 
Pascal Thivent
When I do @OneToOne I get a similar error, it still complains that it cannot find com.xxx.facebook.model.FacebookUser
Mike
Not to say that not having @OneToOne is not a problem...
Mike
@Mike That's weird. Can you show how you annotated `User`? Are all dependencies up-to-date?
Pascal Thivent
I don't think the problem is annotation. When I put the FacebookUser class in my project, everything works fine, but when I move it out into another maven project, when hbm2ddl runs, it doesn't find FacebookUser
Mike
A: 

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

Justin