Need help with Hibernate? Read this first:
Hibernate version:
3.2
Mapping documents:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
<hibernate-mapping package="com.A">
<class name="A"
table="`A`"
dynamic-update="false"
dynamic-insert="false"
select-before-update="false"
optimistic-lock="version"
lazy="true"
batch-size="6"
>
<id name="id" type="java.lang.Long" column="`aID`">
<generator class="native" />
</id>
<property name="ticker" column="`ticker`" type="java.lang.String"
not-null="true" />
</class>
</hibernate-mapping>
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
<hibernate-mapping package="com.B">
<class name="B"
table="`B`"
dynamic-update="false"
dynamic-insert="false"
select-before-update="false"
optimistic-lock="version"
lazy="true"
batch-size="6"
>
<id name="id" type="java.lang.Long" column="`bID`">
<generator class="native" />
</id>
</class>
</hibernate-mapping>
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
<hibernate-mapping package="com.C">
<class name="C"
table="`C`"
dynamic-update="false"
dynamic-insert="false"
select-before-update="false"
optimistic-lock="version"
lazy="true"
batch-size="6"
>
<id name="id" type="java.lang.Long" column="`cID`">
<generator class="native" />
</id>
<many-to-one
name="a"
class="com.A"
column="`aID`"
cascade="all"
not-null="true"
/>
<many-to-one
name="b"
class="com.B"
column="`bID`"
cascade="all"
not-null="true"
/>
</class>
</hibernate-mapping>
I have a requirement for class C, that the combination of A.ticker and B.id needs to be unique. I'd like to be able to apply unique-key somehow on both A.ticker and B.id . However, to apply unique-key I need a reference somehow to A.ticker inside C. The only way I can think of doing that is applying property-ref to A.ticker in C instead of the surrogate key, which doesn't feel like the right solution. Is there another way? Could A.ticker be referenced somehow in C?
Robert