English 中文(简体)
Hibernate @Oneto One with Superclass, onlyrecovery supra Supernal areas on合用
原标题:Hibernate @OneToOne with superclass, only retrieve superclass fields on join

我已经利用“遗产”规划了我在解放国的继承等级。 区分不同实体的单列可变和分立栏。 超级楼的所有子级都将其田地储存到二级表。 例如:

@MappedSuperclass
public abstract class Base
{
   @Id 
   private String id;

   @Version
   private long version;
}

@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "type", discriminatorType = DiscriminatorType.STRING) 
public class Parent extends Base
{
    @Column(nullable=false)
    private BigDecimal value;
}

@Entity
@DiscriminatorValue("child1")
@SecondaryTable(name = "Child1")
public class Child1 extends Parent
{
     @Column(table="Child1")
     private String name;
}

@Entity
@DiscriminatorValue("child2")
@SecondaryTable(name = "Child2")
public class Child2 extends Parent
{
     @Column(table="Child2")
     private String name2;
} 

I now have an Entity that has a @OneToOne relationship with the Parent class. This Entity only needs to work with the value field from the Parent class. It will never need to work with any fields from any subclass of Parent

@Entity
public class AnotherEntity extends Base
{
    @JoinColumn(name="parentId")
    @OneToOne(fetch=FetchType.Lazy, optional=true, targetEntity=Parent.class)
    private Parent parent;
 }

我想要的是,只有父母的领域。 当与父母的关系从数据库中填满时,就选定班级。 我看到的是,自由主义企图把扩大父母的实体的所有财产装上。 它还加入了所有中学。 问题在于我有30个扩大父母的实体。 这使父母实体无法摆脱困境,因为查询过程是30个。

例如,我看到的那类问题就是:

Hibernate: 
select
    parent.id as id3_0_,
    parent_.version as version3_0_,
    parent.name1 as name110_3_0_,
    parent.name2 as name24_3_0_,
    parent.type as type3_0_ 
from
    Parent parent0_ 
left outer join
    Child1 parent0_2_ 
        on parent0_.id=parent0_2_.id 
left outer join
    Child2 parent0_3_ 
        on parent0_.id=parent0_3_.id 

我不理解为什么赫尔辛基决定选择父母子类中界定的所有财产的超级集,并加入所有二级表? 我可以理解,它加入了由提及父母的处分者价值确定的实体的次要表格,但我感到困惑。

我的问题是,我如何满足我的要求,即在我恢复另一个爱情阶层的父母关系时,只能把来自父母阶层的田地装上?

感谢。

最佳回答
问题回答

暂无回答




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签