-->
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.  [ 4 posts ] 
Author Message
 Post subject: Sub-Class with same property/column name (not inherited)
PostPosted: Fri May 04, 2007 4:29 pm 
Beginner
Beginner

Joined: Tue Sep 09, 2003 9:11 pm
Posts: 32
I'm using JBoss 4.0.4 (whichever hibernate version comes with that).

I have the following mapping which works great using a .hbm.xml mapping file. I'm trying to switch to Annotations and can't figure out the correct usage. Any pointers would be appreciated.

Code:
@Entity
@Table(name="bo_entry")
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name="type", discriminatorType=DiscriminatorType.STRING, length=4)
public abstract class AbstractEntry {

   private long id;
   private Company company

   @Id @GeneratedValue
   public long getEntryID(){
      return id;
   }
   public void setEntryID(long id){
      this.id = id;
   }

</snip rest of properties>
}


I have two subclass like:
Code:
@Entity
@DiscriminatorValue("BLIB")
public class BillLiabilityEntry extends AbstractEntry{

   private Bill bill;

   @ManyToOne
   @JoinColumn(name="source")
   public Bill getSource(){
      return bill;
   }
   public void setSource(Bill source){
      this.bill = source;
   }
}
@Entity
@DiscriminatorValue("RINV")
public class InvoiceEntry extends AbstractEntry{

   private Invoice invoice;

   @ManyToOne
   @JoinColumn(name="source")
   public Invoice getSource(){
      return invoice;
   }
   public void setSource(Invoice source){
      this.invoice= source;
   }
}


The corresponding mapping files looks like:
Code:
   <class name="com.IEntry" table="entry" discriminator-value="X" lazy="true">
      <id name="entryID" type="long" unsaved-value="0">
         <generator class="identity"/>
      </id>
      <discriminator column="type" type="string" length="4"/>
      <subclass name="com.InvoiceRevenueEntry" discriminator-value="IREV" lazy="true">
         <many-to-one name="source" class="com.Invoice"/>
      </subclass>
      <subclass name="com.BillLiabilityEntry" discriminator-value="BLIB" lazy="true">
         <many-to-one name="source" class="com.Bill"/>
      </subclass>
   </class>


First, should I be able to map the same property/column in sub-classes?

If so, any suggestions on what I'm doing wrong. I keep getting an error that starts with:
Code:
Caused by: org.hibernate.PropertyAccessException: IllegalArgumentException occurred while calling setter of com.InvoiceRevenueEntry.source
   at org.hibernate.property.BasicPropertyAccessor$BasicSetter.set(BasicPropertyAccessor.java:104)
   at org.hibernate.tuple.AbstractEntityTuplizer.setPropertyValues(AbstractEntityTuplizer.java:330)
   at org.hibernate.tuple.PojoEntityTuplizer.setPropertyValues(PojoEntityTuplizer.java:191)
   at org.hibernate.persister.entity.AbstractEntityPersister.setPropertyValues(AbstractEntityPersister.java:3343)
   at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:129)
   at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:842)
   at org.hibernate.loader.Loader.doQuery(Loader.java:717)
   at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
   at org.hibernate.loader.Loader.doList(Loader.java:2145)
   at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2029)
   at org.hibernate.loader.Loader.list(Loader.java:2024)
   at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:95)
   at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1562)
   at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:283)
   at com.DAAccount.find(DAAccount.java:107)... 80 more
Caused by: java.lang.IllegalArgumentException: argument type mismatch
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:585)
   at org.hibernate.property.BasicPropertyAccessor$BasicSetter.set(BasicPropertyAccessor.java:42)
   ... 136 more



Thanks,
Chris....

_________________
___________
Chris....
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 14, 2007 10:34 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Can you post your running test case to JIRA, there shouldn't be any issue

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 14, 2007 7:44 pm 
Beginner
Beginner

Joined: Tue Sep 09, 2003 9:11 pm
Posts: 32
What format would you guys prefer test cases in?

I'll take a look at the existing cases, just wanted to see if there was anything I should look out for.

Also, it will take me a little while to prepare one. I'm under a deadline; but I want to either fix my code (due to some mistake) or write a valid test case so that Hibernate can be fixed.

Thanks,
Chris....

_________________
___________
Chris....
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 15, 2007 12:28 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
The easiest for us, is to take our unit test suite and create a test from here, so that we can apply the test right away.

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.