-->
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.  [ 2 posts ] 
Author Message
 Post subject: save(Obj) doesn't return the ID (ORACLE trigger)
PostPosted: Wed Apr 20, 2011 7:35 am 
Newbie

Joined: Thu Mar 31, 2011 4:37 am
Posts: 11
Hi guys,

I'm using Hibernate with Oracle10g. My class is mapped to a table. This table id is incremented by an oracle Trigger+sequence.
As soon as i do a save(Obj), the object is correctly saved, a new id is created, but hibernate does not return it...
Here is my bean :
Code:

@Entity
@Table(name = "FAVORITE", schema = "scem", uniqueConstraints = @UniqueConstraint(columnNames = {
      "FAV_U_LOGIN", "FAV_TITLE" }))
public class Favorite implements java.io.Serializable {

   private long favId;
   private Utilisateur utilisateur;
   private String favTitle;
   private Clob favText;

   public Favorite() {
   }

   public Favorite(long favId) {
      this.favId = favId;
   }

   public Favorite(long favId, Utilisateur utilisateur, String favTitle,
         Clob favText) {
      this.favId = favId;
      this.utilisateur = utilisateur;
      this.favTitle = favTitle;
      this.favText = favText;
   }

   @Id
   @Column(name = "FAV_ID", unique = true, nullable = false, precision = 22, scale = 0)
   public long getFavId() {
      return this.favId;
   }

   public void setFavId(long favId) {
      this.favId = favId;
   }

   @ManyToOne(fetch = FetchType.LAZY)
   @JoinColumn(name = "FAV_U_LOGIN")
   public Utilisateur getUtilisateur() {
      return this.utilisateur;
   }

   public void setUtilisateur(Utilisateur utilisateur) {
      this.utilisateur = utilisateur;
   }

   @Column(name = "FAV_TITLE", length = 30)
   public String getFavTitle() {
      return this.favTitle;
   }

   public void setFavTitle(String favTitle) {
      this.favTitle = favTitle;
   }

   @Column(name = "FAV_TEXT")
   public Clob getFavText() {
      return this.favText;
   }

   public void setFavText(Clob favText) {
      this.favText = favText;
   }
   
   @Transient
   public String getFavTextString(){
      return FormatConverter.JavaClob.clobToString(favText);
   }
   public void setFavTextString(String text){
      favText = FormatConverter.JavaClob.stringToClob(text);
   }
}


Here is my DAO code
Code:
   public PK saveObj(T o) { 
       PK obj = (PK) getSession().save(o);
       System.out.println("ID : " + obj);
       return obj;


Do I have something special to do ?
I tryed to use @GeneratedValue and @SequenceGenerator.
When i use Oracle sequence driven by Hibernate, it works.. But that's not what i want to do.
When i try to specify that i'm using a trigger(i guess with generator="select") it doesn't work.

Thanks.


Top
 Profile  
 
 Post subject: Re: save(Obj) doesn't return the ID (ORACLE trigger)
PostPosted: Thu Apr 28, 2011 8:38 am 
Newbie

Joined: Thu Mar 31, 2011 4:37 am
Posts: 11
Any hint guys ? :/


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

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.