-->
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.  [ 3 posts ] 
Author Message
 Post subject: Need Help: Entity class field without mapping
PostPosted: Fri Feb 13, 2009 5:09 am 
Beginner
Beginner

Joined: Thu Dec 11, 2008 2:30 am
Posts: 47
Im using hibernate with annotations
My database is 'Oracle'

I want to know that is it possible to write a entity class like this :

*Table columns are different from this class field names.


Code:
@Entity
@Table(name="TRN_ODEROFSALE")
public class OrderOfSale implements Serializable {
       private String name;
       private int id;
   
       @Column(name="broker_name")
       public String getName(){
             return name;
       }

       public void setName(String name){
            this.name = name;
       }

       //this have no mapping for a particular column//
       public int getId(){
             return name;
       }

       public void setId(int id){
            this.id= id;
       }
}


Above class there is a mapping column for 'name' field.
But i dont want 'id' field to be inserted.

I did this, but it shows error like this.

'Caused by: java.sql.BatchUpdateException: ORA-00904: "ID": invalid identifier
'


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 13, 2009 5:54 am 
Beginner
Beginner

Joined: Thu Dec 11, 2008 2:30 am
Posts: 47
Hey hey........ I found the solution.

Just put the '@Transient' to the relevant field like this....

Code:
        //this have no mapping for a particular column//
        @Transient
       public int getId(){
             return name;
       }


*Problem solved and this field will not be considered as persistent any longer

Couldn't I get a credit for this reply ? I have only two.... (.-.)

regards,
Dilan....


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 13, 2009 5:56 am 
Expert
Expert

Joined: Fri Jan 30, 2009 1:47 am
Posts: 292
Location: Bangalore, India
The fields which you dont want to be persisted should be decorated with @Transient annotation. In entity classes, all the non transient, non static instance variables are by default persisted.

_________________
Regards,
Litty Preeth


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.