-->
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.  [ 1 post ] 
Author Message
 Post subject: unique-key help needed
PostPosted: Tue Nov 21, 2006 10:04 am 
Beginner
Beginner

Joined: Fri Apr 15, 2005 3:30 pm
Posts: 46
Location: Fortaleza, Brazil
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


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

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.