Does Hibernate allow more than 1 class to be mapped to the same db table? I'm trying to break up a 493 col table into smaller classes with 1-to-1 relationships. See Console dump/stack trace & Mappings.
A previous posting (
http://forum.hibernate.org/viewtopic.ph ... t=onetoone) says
"Hibernate guarantees identical objects (VM identity be memory location) only in the same Session scope. Use equals() to check for equality." This leads me to think I might just need adjustment to the .equals method (see code) but I can't figure out what that would be.
Although, another posting (
http://forum.hibernate.org/viewtopic.ph ... t=onetoone) seems to indicate this is not supported.
"It is an API-level requirement of Hibernate that a class maps unambiguously to a particular table."
jeff.boring@siemens.com
Console Dump/ Stack Trace:
Code:
12:29:19,508 DEBUG Loader:220 - total objects hydrated: 1
12:29:19,508 DEBUG SessionImpl:1986 - resolving associations for [bidAlt.mapManyClasses.BpMBidAlt#1]
12:29:19,518 DEBUG SessionImpl:1782 - loading [bidAlt.mapManyClasses.BpMBidAlt1#1]
12:29:19,518 DEBUG SessionImpl:1874 - attempting to resolve [bidAlt.mapManyClasses.BpMBidAlt1#1]
12:29:19,518 DEBUG SessionImpl:1889 - resolved object in session cache [bidAlt.mapManyClasses.BpMBidAlt1#1]
12:29:19,518 ERROR ReflectHelper:67 - IllegalArgumentException in class: bidAlt.mapManyClasses.BpMBidAlt, setter method of property: bpMBidAlt1
12:29:19,528 ERROR ReflectHelper:71 - expected type: bidAlt.mapManyClasses.BpMBidAlt1, actual value: bidAlt.mapManyClasses.BpMBidAlt
java.lang.IllegalArgumentException: argument type mismatch
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at net.sf.hibernate.util.ReflectHelper$Setter.set(ReflectHelper.java:45)
at net.sf.hibernate.persister.AbstractEntityPersister.setPropertyValues(AbstractEntityPersister.java:182)
at net.sf.hibernate.impl.SessionImpl.initializeEntity(SessionImpl.java:1993)
at net.sf.hibernate.loader.Loader.doResultSet(Loader.java:221)
at net.sf.hibernate.loader.Loader.doFind(Loader.java:113)
at net.sf.hibernate.loader.Loader.loadEntity(Loader.java:661)
at net.sf.hibernate.loader.Loader.loadEntity(Loader.java:676)
at net.sf.hibernate.loader.EntityLoader.load(EntityLoader.java:52)
at net.sf.hibernate.loader.EntityLoader.load(EntityLoader.java:44)
at net.sf.hibernate.persister.EntityPersister.load(EntityPersister.java:354)
at net.sf.hibernate.impl.SessionImpl.doLoad(SessionImpl.java:1920)
at net.sf.hibernate.impl.SessionImpl.doLoadByClass(SessionImpl.java:1787)
at net.sf.hibernate.impl.SessionImpl.load(SessionImpl.java:1718)
at bidAlt.mapManyClasses.Driver.main(Driver.java:76)
rethrown as net.sf.hibernate.PropertyAccessException: IllegalArgumentException occurred while calling: argument type mismatch setter of bidAlt.mapManyClasses.BpMBidAlt.bpMBidAlt1
Mappings:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="bidAlt.mapManyClasses.BpMBidAlt" table="BP_M_BID_ALT" schema="TGBPDBA2">
<id name="bidAltSkey" column="BID_ALT_SKEY" type="java.lang.Long">
<generator class="assigned"/>
</id>
<property name="bidSkey" column="BID_SKEY" type="java.lang.Long" length="12" not-null="true"/>
.......
<one-to-one
name="bpMBidAlt1"
class="bidAlt.mapManyClasses.BpMBidAlt1"
cascade="none"
outer-join="false"
constrained="true"
/>
</class>
</hibernate-mapping>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="bidAlt.mapManyClasses.BpMBidAlt1" table="BP_M_BID_ALT" schema="TGBPDBA2">
<id name="bidAlt1Skey" column="BID_ALT_SKEY" type="java.lang.Long">
<generator class="assigned"/>
</id>
<property name="comBidBondReqdInd" column="COM_BID_BOND_REQD_IND" type="java.lang.String" length="1"/>
....
</class>
</hibernate-mapping>
Code:
Code:
public boolean equals(Object other) {
if ( !(other instanceof BpMBidAlt) ) return false;
BpMBidAlt castOther = (BpMBidAlt) other;
return new EqualsBuilder()
.append(this.getBidAltSkey(), castOther.getBidAltSkey())
.isEquals();
}
public int hashCode() {
return new HashCodeBuilder()
.append(getBidAltSkey())
.toHashCode();
}