-->
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.  [ 4 posts ] 
Author Message
 Post subject: trouble on save or update obj. no error but can't work
PostPosted: Thu Mar 10, 2005 11:25 pm 
Regular
Regular

Joined: Sat Apr 10, 2004 8:39 pm
Posts: 84
trouble on save or update obj. no error but can't work

obj can't save or update to database .

I can't see the insert or update sql.

what happend????????

messages:

[WARN ] [2005-03-11 10:57:06,055] net.sf.ehcache.config.Configurator - No configuration found. Configuring ehcache from ehcache-failsafe.xml found in the classpath: jar:file:/D:/WORK/fjky-fzgs/project/web/WEB-INF/lib/ehcache-1.1.jar!/ehcache-failsafe.xml
xxxxxxxxxxxxxx
Hibernate: select pigeonhole0_.XTYPE_SYMBOL as x0_0_ from PIGEONHOLE_RULE pigeonhole0_ where ((pigeonhole0_.XTYPE_SYMBOL=? ))
Hibernate: select pigeonhole0_.XTYPE_SYMBOL as XTYPE_SY1_2_, pigeonhole0_.SIZE as SIZE2_, pigeonhole0_.PIGEONHOLE_TYPE_SYMBOL as PIGEONHO3_2_, xtype1_.SYMBOL as SYMBOL0_, xtype1_.TITLE as TITLE0_, xtype1_.NOTE as NOTE0_, pigeonhole2_.SYMBOL as SYMBOL1_, pigeonhole2_.TITLE as TITLE1_ from PIGEONHOLE_RULE pigeonhole0_ left outer join XTYPE xtype1_ on pigeonhole0_.XTYPE_SYMBOL=xtype1_.SYMBOL left outer join PIGEONHOLE_TYPE pigeonhole2_ on pigeonhole0_.PIGEONHOLE_TYPE_SYMBOL=pigeonhole2_.SYMBOL where pigeonhole0_.XTYPE_SYMBOL=?
Hibernate: select pigeonhole0_.XTYPE_SYMBOL as XTYPE_SY1_2_, pigeonhole0_.SIZE as SIZE2_, pigeonhole0_.PIGEONHOLE_TYPE_SYMBOL as PIGEONHO3_2_, xtype1_.SYMBOL as SYMBOL0_, xtype1_.TITLE as TITLE0_, xtype1_.NOTE as NOTE0_, pigeonhole2_.SYMBOL as SYMBOL1_, pigeonhole2_.TITLE as TITLE1_ from PIGEONHOLE_RULE pigeonhole0_ left outer join XTYPE xtype1_ on pigeonhole0_.XTYPE_SYMBOL=xtype1_.SYMBOL left outer join PIGEONHOLE_TYPE pigeonhole2_ on pigeonhole0_.PIGEONHOLE_TYPE_SYMBOL=pigeonhole2_.SYMBOL where pigeonhole0_.PIGEONHOLE_TYPE_SYMBOL=?
1

=========================================

code:

public void testSaveOrUpdate() {
PigeonholeRule pigeonholeRule = new PigeonholeRule();
pigeonholeRule.setXtypeSymbol("IMAGE");
pigeonholeRule.setSize(new Integer(2));
PigeonholeType pigeonholeType = new PigeonholeType();
pigeonholeType.setSymbol("none");
pigeonholeRule.setPigeonholeType(pigeonholeType);


pigeonholeRuleDao.saveOrUpdate(pigeonholeRule);
pigeonholeRuleDao.update(pigeonholeRule);
// assertEquals(pigeonholeRule,pigeonholeRuleDao.loadByPrimaryKey("IMAGE"));
try {
Session session = sessionFactory.openSession();
session.saveOrUpdate(pigeonholeRule);
System.out.println("xxxxxxxxxxxxxx");
} catch(Exception e) {
e.printStackTrace();
}
PigeonholeRule obj = pigeonholeRuleDao.loadByPrimaryKey("IMAGE");
System.out.println(obj.getSize());

}


===================================
mapped classes:

public class PigeonholeRule implements Serializable {

private String xtypeSymbol;
private Integer size;
private Xtype xtype;
private PigeonholeType pigeonholeType;
}

public class PigeonholeType implements Serializable {
private String symbol;
private String title;
private PigeonholeRule pigeonholeRule;
}

public class Xtype implements Serializable {
private String symbol;
private String title;
private String note;
private PigeonholeRule pigeonholeRule;
private Set xtypeDefaultActions;
private Set xources;
private Set xtypeActions;
}

_________________
I am the creatxr of world.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 11, 2005 12:10 am 
Regular
Regular

Joined: Sat Apr 10, 2004 8:39 pm
Posts: 84
public Serializable save(PigeonholeRule obj) throws DataAccessException {
Session session = null;
try {
session = sessionFactory.openSession();
session.save(obj);
return obj;
} catch (HibernateException he) {
throw SessionFactoryUtils.convertHibernateAccessException(he);
} finally {
SessionFactoryUtils
.closeSessionIfNecessary(session, sessionFactory);
}
}

_________________
I am the creatxr of world.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 11, 2005 12:33 am 
Regular
Regular

Joined: Sat Apr 10, 2004 8:39 pm
Posts: 84
it seems I've found the error.

I write begainTransation it saved the obj;

session = sessionFactory.openSession();
tx = session.beginTransaction();
session.saveOrUpdate(obj);
tx.commit();

====================
but why DAO class generated by middlegen didn't use transation
it seems it could not use the transaction in codes? is it right?


public void update(CarrierType obj) throws HibernateException
{
Session ss = sessionFactory.getSession()
ss.update(obj);

_________________
I am the creatxr of world.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 11, 2005 2:25 am 
Regular
Regular

Joined: Sat Apr 10, 2004 8:39 pm
Posts: 84
it can update now . but it can't insert new.


[WARN ] [2005-03-11 14:00:52,965] net.sf.ehcache.config.Configurator - No configuration found. Configuring ehcache from ehcache-failsafe.xml found in the classpath: jar:file:/D:/WORK/fjky-fzgs/project/web/WEB-INF/lib/ehcache-1.1.jar!/ehcache-failsafe.xml
Hibernate: select xtype0_.SYMBOL as x0_0_ from XTYPE xtype0_ where (xtype0_.SYMBOL=? )
Hibernate: select xtype0_.SYMBOL as SYMBOL2_, xtype0_.TITLE as TITLE2_, xtype0_.NOTE as NOTE2_, pigeonhole1_.XTYPE_SYMBOL as XTYPE_SY1_0_, pigeonhole1_.SIZE as SIZE0_, pigeonhole1_.PIGEONHOLE_TYPE_SYMBOL as PIGEONHO3_0_, pigeonhole2_.SYMBOL as SYMBOL1_, pigeonhole2_.TITLE as TITLE1_ from XTYPE xtype0_ left outer join PIGEONHOLE_RULE pigeonhole1_ on xtype0_.SYMBOL=pigeonhole1_.XTYPE_SYMBOL left outer join PIGEONHOLE_TYPE pigeonhole2_ on pigeonhole1_.PIGEONHOLE_TYPE_SYMBOL=pigeonhole2_.SYMBOL where xtype0_.SYMBOL=?

SB002

Hibernate: select pigeonhole0_.SYMBOL as x0_0_ from PIGEONHOLE_TYPE pigeonhole0_ where ((pigeonhole0_.SYMBOL=? ))
Hibernate: update PIGEONHOLE_RULE set SIZE=?, PIGEONHOLE_TYPE_SYMBOL=? where XTYPE_SYMBOL=?
[ERROR] [2005-03-11 14:00:57,168] net.sf.hibernate.impl.SessionImpl - Could not synchronize database state with session
org.springframework.orm.hibernate.HibernateSystemException: Batch update row count wrong: 0; nested exception is net.sf.hibernate.HibernateException: Batch update row count wrong: 0
net.sf.hibernate.HibernateException: Batch update row count wrong: 0
Hibernate: select pigeonhole0_.XTYPE_SYMBOL as x0_0_ from PIGEONHOLE_RULE pigeonhole0_ where ((pigeonhole0_.XTYPE_SYMBOL=? ))




public void testSaveOrUpdate() {
PigeonholeRule pigeonholeRule = new PigeonholeRule();

pigeonholeRule.setXtypeSymbol("SB002");
pigeonholeRule.setSize(new Integer(1));
Xtype xtype = xtypeDao.loadByPrimaryKey("SB002");
System.out.println(xtype.getTitle());
pigeonholeRule.setXtype(xtype);
pigeonholeRule.setPigeonholeType(pigeonholeTypeDao.loadByPrimaryKey("SB002"));

// PigeonholeType pigeonholeType = new PigeonholeType();
// pigeonholeType.setSymbol("none");
// pigeonholeType.setTitle("SB002");
// pigeonholeRule.setPigeonholeType(pigeonholeType);
// Xtype xtype = new Xtype();
// xtype.setSymbol("SB002");

// assertEquals(pigeonholeRule,pigeonholeRuleDao.loadByPrimaryKey("SB002"));
try {
pigeonholeRuleDao.saveOrUpdate(pigeonholeRule);

// pigeonholeRuleDao.update(pigeonholeRule);

Session session = sessionFactory.openSession();

// Transaction tran = session.beginTransaction();
// session.saveOrUpdate(pigeonholeRule);
// tran.commit();
System.out.println("xxxxxxxxxxxxxx");
} catch(Exception e) {
e.printStackTrace();
}

PigeonholeRule obj = pigeonholeRuleDao.loadByPrimaryKey("SB002");
System.out.println(obj.getSize());

}

_________________
I am the creatxr of world.


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