-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Hibernate table per class hierarchy with explicit polymorphi
PostPosted: Thu Aug 21, 2014 6:06 am 
Beginner
Beginner

Joined: Tue Nov 21, 2006 5:18 am
Posts: 31
Location: Bangalore, India
I'm getting **IllegalArgumentException** while saving an dynamic entity,

I have two classes as **SuperClassImpl** and **SubClassImpl**, which are mapped using table per class hierarchy. Also, I used the explicit polymorphism to use same POJO for two different tables.

<class name="SuperclassImpl" polymorphism="explicit" table="super_class" mutable="true" discriminator-value="1000">
<id name='id' type='long'>
<discriminator column="data" type="int"/>
<version name='version'/>
<property name="entry"/>
<subclass name="SupclassImpl" discriminator-value="1">
<property name="subId" column="sub_id" type="long"/>
</subclass>
</class>

<class name="SuperclassImpl" entity-name="SuperclassImplHist" table="super_class_hist" mutable="true" discriminator-value="1000">
<composite-id>
<key-property name="id" type="long"/>
<key-property name="fromDate" type="imm_timestamp"/>
</composite-id>
<discriminator column="data" type="int"/>
<property name="entry"/>
<subclass name="SupclassImpl" entity-name="SupclassImplHist" discriminator-value="1">
<property name="subId" column="sub_id" type="long"/>
</subclass>
</class>


public class SuperClassImpl implements Serializable {
private Long id;
private int version;
private String entry;

public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}

public String getEntry() {
return entry;
}

public void setEntry(String entry) {
this.entry = entry;
}

}

public class SubClassImpl extends SuperClassImpl {

private Date fromDate;
private Long subId;

public Date getFromDate() {
return fromDate;
}

public void setFromDate(Date fromDate) {
this.fromDate = fromDate;
}

public Long getSubId() {
return id;
}

public void setSubId(Long subId) {
this.subId = subId;
}

}

/*this below code works and saves the entity*/
SuperClassImpl sci = new SuperClassImpl();
pbe.setId(109305L);
pbe.setEntry("started");
pbe.setFromDate(new Date());
HibernateUtil.currentSession().save("SuperClassImplHist", sci);


/*not working and throws exception
Caused by: java.lang.IllegalArgumentException: Can not set java.lang.Long field SubClassImpl.id to java.lang.Long*/
SubClassImpl sci = new SubClassImpl();
pbe.setId(109321L);
pbe.setSubId(2123L);
pbe.setEntry("started");
pbe.setFromDate(new Date());
HibernateUtil.currentSession().save("SubClassImplHist", sci);


Do you see any issues with the code or mapping? While saving the **SubClassImplHist** I get this exception

"java.lang.IllegalArgumentException: Can not set java.lang.Long field SubClassImpl.id to java.lang.Long"


Many thanks for your answers.


Top
 Profile  
 
 Post subject: Re: Hibernate table per class hierarchy with explicit polymorphi
PostPosted: Sat Aug 23, 2014 3:12 am 
Beginner
Beginner

Joined: Tue Nov 21, 2006 5:18 am
Posts: 31
Location: Bangalore, India
After half a day of code debug, found that it's indeed a bug in the hibernate version I'm using which is in hibernate version 3.0.

The issue was in the code file org.hibernate.tuple.entity.EntityMetamodel in the method

public String findEntityNameByEntityClass(Class inheritenceClass) {
return ( String ) entityNameByInheritenceClassNameMap.get( inheritenceClass.getName() );
}The entityNameByInheritenceClassNameMap is holding the key with Class type. For my problem I have no fix with the current hibernate version.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.