-->
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: how to only load variables declared to be bind
PostPosted: Wed Nov 28, 2007 11:01 am 
Newbie

Joined: Wed Nov 28, 2007 10:26 am
Posts: 2
Hibernate version: 3.2

Hi I am using hibernate 3.2 to map my objects with my oracle database and I am using annotations.

my question is :
Can I use in my object, variable that does not bind a column ?

let me explain a bit :)
I have an object Actrivity which binds an oracle table.
This table has 2 fields: id, mode.


I declare the first variable as the following:
@Column(name="id")
Double id;

I do not want hibernate loads this second field but I want to be able to use the variable
Double mode;

finally I want to use a boolean flag which is not a table field
boolean myFlag;


Here is the behavior I get and seems a bit strange to me.

'id' is loaded and I can get the value with the getter : ok
'mode' is loaded despite I did not write '@Column(name="mode")'
'myFlag' rises an ORA 00904 exception which is : the column 'myFlag' does not exist

so is it possible hibernate loads automatically the field declared in the classe ?
how to avoid that ?
The behavior I would like/expect is : only the variables declared to be bind (with the @annotation) should be loaded !
and how to use a class variable which is not a table field without getting an error ?

thanks for your help

Here is the stacktrace
org.hibernate.exception.SQLGrammarException: could not execute query
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.doList(Loader.java:2214)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2095)
at org.hibernate.loader.Loader.list(Loader.java:2090)
at org.hibernate.hql.classic.QueryTranslatorImpl.list(QueryTranslatorImpl.java:888)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:172)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1121)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
at com.aureus_pharma.saio.core.Activity.retrieveActivitiesFromIdTargetList(Activity.java:270)
at com.aureus_pharma.profiler.ProfilerControler.launchTargetQuery(ProfilerControler.java:750)
at com.aureus_pharma.profiler.query.TargetPane$1.run(TargetPane.java:218)
at java.lang.Thread.run(Thread.java:619)
Caused by: java.sql.SQLException: ORA-00904: "ACTIVITY0_"."myFlag" : identificateur non valide


database : Oracle 9i


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 28, 2007 8:02 pm 
Newbie

Joined: Sat Dec 25, 2004 11:18 pm
Posts: 11
All fields not annotated would be given suitable defualts. So your field mode binds to mode column in table. You can use @Transient annotation to tell hibernate that field is not bound to database.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 29, 2007 4:41 am 
Newbie

Joined: Wed Nov 28, 2007 10:26 am
Posts: 2
Hi mananmehra,

thanks for your help it works fine now


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.