hibernate3-maven-plugin:不同maven项目中的条目,hbm2ddl失败

发布于 2024-08-31 21:37:55 字数 2292 浏览 10 评论 0原文

我正在尝试将一个实体放入不同的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

固执像三岁 2024-09-07 21:37:55

FacebookUser 不是基本类型,不能持久保存在 User 表的列中,它是实际持久保存在另一个表中的真实实体。这里有 UserFacebookUser 之间的一对一关系,您需要这样声明:

@OneToOne
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;
} 
遗忘曾经 2024-09-07 21:37:55

您可能想尝试将依赖项添加为“测试”,而不仅仅是编译。
来自 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:

Requires dependency resolution of
artifacts in scope: test

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文