-->
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: Getting Problem While Doing Update...Very Interesting
PostPosted: Fri Oct 12, 2007 2:13 am 
Newbie

Joined: Fri Oct 05, 2007 3:46 am
Posts: 3
Location: HyderaBad
Hi All,

I am having my mapping like :
<class name="X" table="x" lazy="true"
dynamic-insert="true" >
<id name="xID" column="x_ID">
<generator class="native"/>
</id>
<property name="name" column="NAME" lazy="true"/>
<property name="desc" column="DESC" lazy="true"/>
<many-to-one name="y" class="Y"
column="x_ID" property-ref="xID" insert="false"
update="false" />
<many-to-one name="z" class="Z"
column="x_ID" property-ref="xID"
insert="false" update="false" />
</class>

Now My update Method is like :
public boolean editData(final ServiceBean s) {
if(s == null) {
throw new IllegalArgumentException("s can not be null");
}

TransactionTemplate template =
new TransactionTemplate(this.transactionManager);
template.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);

try {
template.execute(new TransactionCallback() {
public Object doInTransaction(TransactionStatus transactionState) throws HibernateException {
getHibernateTemplate().execute(new HibernateCallback() {
public Object doInHibernate(Session session) throws HibernateException, SQLException {
// I tried with following methods :
One is this...
String hqlQuery = new StringBuilder("FROM X x ")
.append("WHERE ")
.append("x.xID = ")
.append(+s.getID())
.toString();
Query query = session.createQuery(hqlQuery);
List aList = query.list();
for(Object object : aList) {
X x = (X)object;

x.setName(s.getName());
// note I am not setting desc here
getHibernateTemplate().update(x);

Another is this :
Integer id = new Integer(s.getID());
X x = (X)session.load(X.class, id);

x.setName("D");
getHibernateTemplate().update(x);
}
return null;
}
});
return null;
}
});
} catch(Exception exp) {
exp.printStackTrace();
return false;
}
return true;
}


Now I am getting this error :

Hibernate: select x0_.x_ID as x_35_2_, x0_.NAME as x2_35_2_, x0_.DESC as x12_35_2_, y1_.Y_ID as y1_22_0_, z2_.Z_ID as Z1_16_1_ from X x0_ left outer join Y y1_ on x0_.X_ID=y1_.Y_ID left outer join Z z2_ on x.X_ID=z.Z_ID where x0_.X_ID=?
Hibernate: select y0_.Y_ID as Y1_27_0_ from Y y0_ where y0_.Y_ID=?
Hibernate: select z0_.Z_ID as z1_20_0_ from Z z0_ where z0_.Z_ID=?


org.springframework.orm.hibernate3.HibernateSystemException: Null value was assigned to a property of primitive type setter of X.xID; nested exception is org.hibernate.PropertyAccessException: Null value was assigned to a property of primitive type setter of X.xID Caused by: org.hibernate.PropertyAccessException: Null value was assigned to a property of primitive type setter of X.xID at org.hibernate.property.BasicPropertyAccessor$BasicSetter.set(BasicPropertyAccessor.java:85)
at org.hibernate.tuple.entity.AbstractEntityTuplizer.setPropertyValues(AbstractEntityTuplizer.java:337)
at org.hibernate.tuple.entity.PojoEntityTuplizer.setPropertyValues(PojoEntityTuplizer.java:200)
at org.hibernate.persister.entity.AbstractEntityPersister.setPropertyValues(AbstractEntityPersister.java:3566)
at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:129)
at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:854)
at org.hibernate.loader.Loader.doQuery(Loader.java:729)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
at org.hibernate.loader.Loader.loadEntity(Loader.java:1860)
at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:48)
at org.hibernate.loader.entity.EntityLoader.loadByUniqueKey(EntityLoader.java:85)
at org.hibernate.persister.entity.AbstractEntityPersister.loadByUniqueKey(AbstractEntityPersister.java:1645)
at org.hibernate.type.EntityType.loadByUniqueKey(EntityType.java:608)
at org.hibernate.type.EntityType.resolve(EntityType.java:382)
at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:116)
at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:854)
at org.hibernate.loader.Loader.doQuery(Loader.java:729)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
at org.hibernate.loader.Loader.loadEntity(Loader.java:1860)
at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:48)
at org.hibernate.loader.entity.EntityLoader.loadByUniqueKey(EntityLoader.java:85)
at org.hibernate.persister.entity.AbstractEntityPersister.loadByUniqueKey(AbstractEntityPersister.java:1645)
at org.hibernate.type.EntityType.loadByUniqueKey(EntityType.java:608)
at org.hibernate.type.EntityType.resolve(EntityType.java:382)
at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:116)
at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:854)
at org.hibernate.loader.Loader.doQuery(Loader.java:729)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
at org.hibernate.loader.Loader.loadEntity(Loader.java:1860)
at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:48)
at org.hibernate.loader.entity.EntityLoader.loadByUniqueKey(EntityLoader.java:85)
at org.hibernate.persister.entity.AbstractEntityPersister.loadByUniqueKey(AbstractEntityPersister.java:1645)
at org.hibernate.type.EntityType.loadByUniqueKey(EntityType.java:608)
at org.hibernate.type.EntityType.resolve(EntityType.java:382)
at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:116)
at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:854)
at org.hibernate.loader.Loader.doQuery(Loader.java:729)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
at org.hibernate.loader.Loader.loadEntity(Loader.java:1860)
at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:48)
at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:42)
at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:3044)
at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:395)
at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:375)
at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:139)
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:98)
at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:878)
at org.hibernate.impl.SessionImpl.immediateLoad(SessionImpl.java:836)
at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:66)
at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:111)
at org.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer.invoke(CGLIBLazyInitializer.java:150)
org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:372)
at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:338)
at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:127)
Caused by: java.lang.IllegalArgumentException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.hibernate.property.BasicPropertyAccessor$BasicSetter.set(BasicPropertyAccessor.java:42)
... 58 more



I am not in favour to write a select for all fields of table and set all values in bean. and If I am selecting the fields which are required to update. Other fields are getting updated with default values set in Database.

Is There a some solution to resolve this problem ?
If you thinks for some link to be useful or have a solution. please give me that. I will be thankful to you.

THANKS,
GOPAL


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 12, 2007 4:17 am 
Beginner
Beginner

Joined: Thu Feb 08, 2007 11:11 am
Posts: 24
Location: India
One of your field is having a NULL value, but that is of primitive type. Check that and change to the wrappe class. I think that'll be enough to solve the problem.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 12, 2007 4:52 am 
Newbie

Joined: Fri Oct 05, 2007 3:46 am
Posts: 3
Location: HyderaBad
Hi Supriyo,

Thanks for your reply but I am not updating desc field which is of type String. and its value is updated to null.

Thanks,
Gopal


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.