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....