hibernate3-maven-plugin:不同maven项目中的条目,hbm2ddl失败
我正在尝试将一个实体放入不同的 Maven 项目中。在当前项目中,我有:
@Entity
public class User {
...
private FacebookUser facebookUser;
...
public FacebookUser getFacebookUser() {
return facebookUser;
}
...
public void setFacebookUser(FacebookUser facebookUser) {
this.facebookUser = facebookUser;
}
然后 FacebookUser (在不同的 Maven 项目中,这是当前项目的依赖项)定义为:
@Entity
public class FacebookUser {
...
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
public Long getId() {
return id;
}
这是我的 Maven hibernate3-maven-plugin 配置:
<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>
这是我收到的错误:
org.hibernate.MappingException: Could not determine type for: com.xxx.facebook.model.FacebookUser, at table: user, for columns: [org.hibernate.mapping.Column(facebook_user)]
我知道FacebookUser 位于类路径上,因为如果我将 facebook 用户设置为瞬态,则项目可以正常编译:
@Transient
public FacebookUser getFacebookUser() {
return facebookUser;
}
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;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
FacebookUser
不是基本类型,不能持久保存在User
表的列中,它是实际持久保存在另一个表中的真实实体。这里有User
和FacebookUser
之间的一对一关系,您需要这样声明:A
FacebookUser
is not a basic type and can't be persisted in a column of theUser
table, it's a real entity that is actually persisted in another table. What you have here is a one-to-one relation betweenUser
andFacebookUser
and you need to declare it as such:您可能想尝试将依赖项添加为“测试”,而不仅仅是编译。
来自 http://mojo.codehaus.org/maven -hibernate3/hibernate3-maven-plugin/hbm2ddl-mojo.html:
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: