【问题标题】:Embbedable hibernate annotation is not working可嵌入的休眠注释不起作用
【发布时间】:2016-09-11 19:07:47
【问题描述】:

我实际上正在学习休眠,我认为 @Embbebed 和 @Embbedable 对我不起作用

我知道了:

@Entity
public class Poi {
@Id @GeneratedValue
private long id;

@Embedded
private PoiType poiType;

private String name;

@SuppressWarnings("unused")
private Poi(){}

public Poi(PoiType type,String name) {
    this.poiType = type;
    this.name = name;
}

@Embeddable
public class TypeA extends PoiType {

private Integer number;

@SuppressWarnings("unused")
private TypeA(){}

public TypeA(Integer num) {
    this.number=num;
}

XML

<?xml version="1.0" encoding="UTF-8"?> 
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence 
    http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd" 
    version="1.0"> 


<persistence-unit name="db" transaction-type="RESOURCE_LOCAL">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>


    <class>tpAnual.POIs.Poi</class>
    <class>tpAnual.POIs.PoiType</class>
    <class>tpAnual.POIs.TypeA</class>



    <properties> 
    <property name="hibernate.archive.autodetection" value="class"/>        

        <property name="hibernate.connection.driver_class" value="org.hsqldb.jdbcDriver" /> 
        <property name="hibernate.connection.url" value="jdbc:hsqldb:mem:app-db" /> 
        <property name="hibernate.connection.username" value="sa" /> 
        <property name="hibernate.connection.password" value="" /> 
        <property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect" />


        <property name="hibernate.show_sql" value="true" /> 
        <property name="hibernate.format_sql" value="true" /> 
        <property name="use_sql_comments" value="true" /> 
        <property name="hibernate.hbm2ddl.auto" value="update" />

    </properties>

</persistence-unit> 

当我运行测试(一切设置正确)时,控制台只输出:

休眠: 插入 进入 泊 (身份证,姓名) 价值观 (默认,?)

我错过了什么?非常感谢!

【问题讨论】:

    标签: java hibernate annotations persistence


    【解决方案1】:

    嵌入实体中的继承几乎没有意义,因为它根据嵌入实体的实际类在包含实体表中调用一组不同的列,但是在声明时,ORM 对可能从要嵌入的基类派生的类。我听说 EclipseLink 以某种方式做到了,(我什至不想想到他们做了什么样的恶行来拉这个把戏,)但据我所知,hibernate 不支持它。

    【讨论】:

      猜你喜欢
      • 2011-02-02
      • 1970-01-01
      • 2016-07-12
      • 1970-01-01
      • 1970-01-01
      • 2012-08-05
      • 2015-12-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多