Results 1 to 5 of 5

Thread: primary key problem

  1. #1

    Default primary key problem

    Hi
    I've table with id, appid and some more columns
    ID here is this table ID which increments by default. whereas appid is the one whoch has one-tomany relationship with otehr tables

    my hbm.xml is like this while reading data it's ok but while writing data I'm getting error as hsql created tried to set ID which is automatically generated key. Can somebody pelase help me.

    Table a hbm.xml

    Code:
    <hibernate-mapping>
        <class name="AccountOpenVO" table="ACCOPEN">
        
         <id name="appid" column="appid" type="java.lang.Integer" unsaved-value="null">
    </id> 
        <property name="Id" column="id" type="java.lang.Integer" not-null="true" />
         <set name="customers"   table="ACCCUST" lazy="false">
            <key column="dia_accopenid" />
                <one-to-many  class="AccountCustVO"  />
             </set> 
          <set name="products"   table="ACCPROD" lazy="false">
            <key column="dia_accopenid" />
                <one-to-many class="AccountProdVO" />
             </set>
                <property name="runno"  column="runind"  type="java.lang.Integer" not-null="true"/>
    </class>

  2. #2
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,425

    Default

    If you have an association, then you should map this rather than the property.
    http://www.hibernate.org/hib_docs/v3...ional-join-12m
    Last edited by karldmoore; Aug 29th, 2007 at 11:15 AM.
    Barracuda Networks SSL VPN Lead Developer
    http://pramatr.wordpress.com
    http://twitter.com/karldmoore
    http://www.linkedin.com/in/karldmoore
    Any postings are my own opinion, and should not be attributed to my employer or clients.

  3. #3

    Default

    Quote Originally Posted by karldmoore View Post
    If you have an association, then you should map this rather than the property.
    http://www.hibernate.org/hib_docs/v3...ional-join-12m
    Hi
    in my case it is not the primary key having one-to-many relation. how do i declare the set with another column.
    for eg., here it is "appid" having relation with other table column "accopenid"
    please show me some example.

    thanks

  4. #4
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,695

    Default

    use the property-ref option on the key element.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  5. #5

    Default

    Hi Here is the more clear picture of my mapping problem


    in my case it is not the primary key having one-to-many relation. how do i declare the set with another column.
    for eg., here it is "appid" in table A(which is non pri key) having relation with other table column "accopenid" which is again non-primary key in tableB
    please show me some example.

    thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •