-->
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.  [ 1 post ] 
Author Message
 Post subject: HQL Update statement issue
PostPosted: Tue Jan 15, 2008 10:51 am 
Newbie

Joined: Tue May 08, 2007 3:34 pm
Posts: 19
This problem has been resolved: I did not include a step to set the session object in the dao. Kind of easy mistake, since no failure was being reported and it displayed one row updated. Misleading.... Thanks anyway.

I am having a problem with the below code. The output on 15Jan is from the log file and the query gets created, executes and returns one row updated. The data does not reflect being update though in the DB. I am using 3.1.3 Hibernate. I checked the schema name and database and I am sure it is pointing to this database. The table definitions are not defined in any other db, so it would definitely not work.

Another point is I can take out the exact SQL that is dynamically and run it and it updates the data correctly.

Everything indicates that it is working fine, but the db does not get updated.

this is the test function not working ->
this.setBooleanAttribute("JL_0", 1, "Inbox",
"ENABLE_TRANS_FLG", true);

Any ideas what is wrong?
Your help is appreciated.
Joe


15 Jan 2008 09:43:57 [0_217=GetCustomProperties] DEBUG -UPDATE SETBOOLEAN
15 Jan 2008 09:43:57 [0_217=GetCustomProperties] DEBUG -role_id=1
15 Jan 2008 09:43:57 [0_217=GetCustomProperties] DEBUG -journal_code=JL_0
15 Jan 2008 09:43:57 [0_217=GetCustomProperties] DEBUG -module=Inbox
15 Jan 2008 09:43:57 [0_217=GetCustomProperties] DEBUG -attribute=ENABLE_TRANS_FLG
15 Jan 2008 09:43:57 [0_217=GetCustomProperties] DEBUG -rows updated=1
15 Jan 2008 09:43:57 [0_217=GetCustomProperties] INFO -queryString=update CustomAttributeInstance set VALUE = 'Y' where ROLE_ID = 1 and JOURNAL_CODE ='JL_0' and MODULE ='Inbox' and ATTRIBUTE ='ENABLE_TRANS_FLG' and VALUE in ('Y', 'N')


public void setBooleanAttribute(String journal_code,
int role_id, String module, String attribute, boolean value)
throws CustomizationException{
log.info("Entering setBooleanAttribute");

String value_bool = null;
if(value==true){
logger.debug("value is true");
value_bool="Y";
}
else{
logger.debug("value is false");
value_bool="N";
}

try {
String queryString = "update CustomAttributeInstance " +
" set VALUE = '" + value_bool + "'" +
" where ROLE_ID = " + role_id +
" and JOURNAL_CODE ='" + journal_code + "'" +
" and MODULE ='" + module + "'" +
" and ATTRIBUTE ='" + attribute + "'" +
" and VALUE in ('Y', 'N')";

Query queryObject = getSession().createQuery(queryString);
int retValue =
queryObject.executeUpdate();

logger.debug("UPDATE SETBOOLEAN");
logger.debug("role_id=" + role_id);
logger.debug("journal_code=" + journal_code);
logger.debug("module=" + module);
logger.debug("attribute=" + attribute);
logger.debug("rows updated=" + retValue);

logger.info("queryString=" + queryString);
} catch (RuntimeException re) {
log.error("runtime exception: ", re);
throw new CustomizationException(re);
}
finally{
log.info("Leaving setBooleanAttribute");
}
}










String sqlQuery = null;
m_schema = schema;
SessionFactory sf = this.getSessionFactoryFromApplicationObject();
Session session = sf.openSession();
Transaction tx = null;

module = new Module();
moduleDao = new ModuleDAO();
customAttributes = new CustomAttributes();
customAttributesDao = new CustomAttributesDAO();
customAttributeInstance =
new CustomAttributeInstance();
customAttributeInstanceDao =
new CustomAttributeInstanceDAO();


try
{
tx = session.beginTransaction();
Journal journal = new Journal();
JournalDisciplines dis = new JournalDisciplines();
JournalSections js = new JournalSections();
MsStatus msStatus = new MsStatus();
JournalMsStatus msStatusNew = new JournalMsStatus();
MsType mst = new MsType();
JournalPerformanceCriteria jpc = new JournalPerformanceCriteria();
Country ctry = new Country();

List configurableModuleList =
moduleDao.getModules();
Iterator it = configurableModuleList.iterator();

if(configurableModuleList.size() > 0){
int i=0;
while(it.hasNext()){
module = (Module)
configurableModuleList.get(i++);
moduleMap.put(new Integer(i),
module.getModule());
it.next();
}
logger.info("moduleMap="+ moduleMap);
}

List roleAttributeList = customAttributesDao.getCustomAttributes();
it = roleAttributeList.iterator();
String valueString = null;

if(roleAttributeList.size() > 0){
int i=0;

while(it.hasNext()){
customAttributes = (CustomAttributes)
roleAttributeList.get(i++);
valueString =
customAttributes.getId().getModule()+ ":" +
customAttributes.getAttributeDatatype()+ ":" +
customAttributes.getDescription()+ ":" +
customAttributes.getDefaultValue()+ ":" +
customAttributes.getPrivilegedToCustomizeYn();
customAttributeMap.put(
customAttributes.getId().getAttribute(),
valueString);
it.next();
}
logger.info("customAttributeMap="+ customAttributeMap);
}


List roleConfigurationList =
customAttributeInstanceDao.getCustomAttributeInstanceObjects();

it = roleConfigurationList.iterator();

if(roleConfigurationList.size() > 0){
int i=0;

while(it.hasNext()){
customAttributeInstance = (CustomAttributeInstance)
roleConfigurationList.get(i++);

valueString = customAttributeInstance.getId().getJournalCode()
+ ":" +
customAttributeInstance.getId().getRoleId()+ ":" +
customAttributeInstance.getId().getAttribute();
customAttributeInstancesMap.put(valueString,
customAttributeInstance.getValue() );
it.next();
}
logger.info("customAttributeInstancesMap="+
customAttributeInstancesMap);
}
//TESTING - do some tests and clean up this block at some point....
this.getModules();

boolean check_bool =
this.getBooleanAttributes("JL_0", 1, "Inbox", "ENABLE_TRANS_FLG");
logger.info("check_bool=" + check_bool);

try{
String check_string =
this.getStringAttributes("JL_0", 1, "Inbox", "TENABLE_TRANS_FLG");
logger.info("check_string=" + check_string);
}
catch(CustomizationException ce){
logger.info("string ce=" + ce);
}

try{
int check_int =
this.getNumberAttributes("JL_0", 1, "Inbox", "NENABLE_TRANS_FLG");
logger.info("check_int=" + check_int);
}
catch(CustomizationException ce){
logger.info("number ce=" + ce);
}

try{

this.setBooleanAttribute("JL_0", 1, "Inbox",
"ENABLE_TRANS_FLG", true);


}
catch(CustomizationException ce){
logger.info("boolean ce=" + ce);
}

try{
this.setStringAttribute("JL_0", 1, "Inbox",
"TENABLE_TRANS_FLG", "Yippie i a");

}
catch(CustomizationException ce){
logger.info("string ce = " + ce);
}
tx.commit();

logger.info("committing transaction");

//TESTING


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

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.