-->
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: A suggestion
PostPosted: Mon Oct 30, 2006 6:17 am 
Regular
Regular

Joined: Thu Feb 24, 2005 2:34 pm
Posts: 80
Ok it's very stupid example but it's very important for my knowldge in hibernate.
My primary key is PKID (surrogate key) in this case a db sequence.
My business key is email field. Then i won't that exists 2 user with the same email into a table.
About you it's a good approach this for my business key
Thanks in advance
Devis
Have you some link or example for to understand better this concept?

Code:
           TuserDAO dao = new TuserDAO();
      List li = dao.findByEmail("devis@devis.it");
      Tuser vo = null;
      if(li.size()<=0)
         vo=new Tuser();
      else
         vo=(Tuser)li.get(0);
      vo.setEmail("user@user.it");
      vo.setDescr("Ciao");
      dao.getSession().getTransaction().begin();
      dao.SaveOrUpdate(vo);   
      dao.getSession().getTransaction().commit();

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!--
    Mapping file autogenerated by MyEclipse - Hibernate Tools
-->
<hibernate-mapping>

    <class name="com.vo.Tuser" table="TUSER" schema="DEVIS" dynamic-update="true">
        <id name="pkid" type="java.lang.Long">
            <column name="PKID" precision="22" scale="0" />
            <generator class="sequence">
            <param name="sequence">TUSER_SEQ</param>
            </generator>
        </id>
        <version name="version" type="java.util.Date" column="VERSION" />

        <property name="email" type="java.lang.String" unique="true">
            <column name="email"  not-null="true" />
        </property>
        <property name="descr" type="java.lang.String">
            <column name="DESCR" length="100" />
        </property>
    </class>
</hibernate-mapping>



In my dao class
      TuserDAO dao = new TuserDAO();
      List li = dao.findByEmail("devis@devis.it");
      Tuser vo = null;
      if(li.size()<=0)
         vo=new Tuser();
      else
         vo=(Tuser)li.get(0);
      vo.setEmail("user@user.it");
      vo.setDescr("Ciao");
      dao.getSession().getTransaction().begin();
      dao.SaveOrUpdate(vo);   
      dao.getSession().getTransaction().commit();


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.