-->
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: Problem Retrieving a Specific String
PostPosted: Tue Feb 10, 2009 12:48 pm 
Newbie

Joined: Tue Feb 10, 2009 12:32 pm
Posts: 2
I am very new to hibernate and working with an implementation set up by a colleague who has recently left the company. Apologies if the answer is basic.

I seem to have a problem retrieving a simple persisted property using hibernate. The value gets persisted fine; but during retrieval a proxy exception occurs in an unexpected part of the domain model.

The value that causes the failure is:
F!MCF!E!{F!!BRS!891B5!ALC!MC!MC!1234&F!!ALC!898Gj!BRS!MC!MC!5678}

The mapping file and everything works fine if I substitute this result for a fake example; for example 'test' or remove the simple property declaration form my mapping file. It then persists and retrieves the value correctly. So I am wondering if the issue is something to do with the data itself?

As far as I am aware the connection, query, mapping file and all other usages are correct (as the simple 'test' substitution works - this is just a change to the data only).


Hibernate version:
3,2,4

Name and version of the database you are using:
Postgres 8.2

Mapping Fragment:
<property name="identity"/>

Stack Trace:
org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.xmltravel.fab.flights.domain.Flight.personReferences, no session or session was closed
at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:358)
at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationExceptionIfNotConnected(AbstractPersistentCollection.java:350)
at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:343)
at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:86)
at org.hibernate.collection.PersistentList.iterator(PersistentList.java:115)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 10, 2009 6:03 pm 
Newbie

Joined: Fri Jan 30, 2009 5:08 pm
Posts: 17
Location: Florida
I don't have Postgres but it works fine with MySql and Hibernate 3.3.1 GA and the code below... I hope it helps

Hibernate: insert into test (val) values (?)
Hibernate: select testvo0_.test_id as test1_0_, testvo0_.val as val0_ from test testvo0_ where testvo0_.test_id=1
F!MCF!E!{F!!BRS!891B5!ALC!MC!MC!1234&F!!ALC!898Gj!BRS!MC!MC!5678}



create table test (
test_id int not null auto_increment,
val varchar(255),
primary key(test_id));

DataService.java
package com.example.apps.reports.service;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.hibernate.Session;
import com.example.apps.reports.dao.HibernateUtil;
import com.example.apps.reports.vo.TestVo;
public class DataService {
public static void saveItem(ValueObject vo){
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
session.saveOrUpdate(vo);
session.getTransaction().commit();
}
public static void main(String[] args) {
TestVo t = new TestVo();
t.setTestId(1);
t.setVal("F!MCF!E!{F!!BRS!891B5!ALC!MC!MC!1234&F!!ALC!898Gj!BRS!MC!MC!5678}");
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
session.save(t);

session.getTransaction().commit();

session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
t = (TestVo) session.createQuery("from TestVo where testId = 1").uniqueResult();
session.getTransaction().commit();

System.out.println(t.getVal());

}
}
TestVo.java
package com.example.apps.reports.vo;

public class TestVo {
private int testId;
private String val;

public String getVal() {
return val;
}
public void setVal(String val) {
this.val = val;
}
public int getTestId() {
return testId;
}
public void setTestId(int testId) {
this.testId = testId;
}
}

TestVo.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
<class name="com.example.apps.reports.vo.TestVo" table="test">
<id name="testId" column="test_id">
<generator class="native"/>
</id>
<property name="val" column="val" type="java.lang.String"/>
</class>
</hibernate-mapping>

hibernate.cfg.xml
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost/hibernatetest</property>
<property name="connection.username">root</property>
<property name="connection.password"></property>
<property name="connection.pool_size">1</property>
<property name="dialect">org.hibernate.dialect.MySQLInnoDBDialect</property>
<property name="current_session_context_class">thread</property>
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<property name="show_sql">true</property>
<property name="hbm2ddl.auto">create</property>
<mapping resource="com/example/apps/reports/vo/mappings/TestVo.hbm.xml"/>
</session-factory>
</hibernate-configuration>


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 10, 2009 7:10 pm 
Newbie

Joined: Tue Feb 10, 2009 12:32 pm
Posts: 2
Thanks WarpedCodeMonkey.

I really appreciate you going to that effort, it is very professional of you; I did not consider making up a test case.

Well it i interesting to know that it works as that cuts down some uncertainty on an issue that is currently baffling me! I will check the system I have against MySQL and also run your test case against postgres when I return to work.

Thanks fro your time and help.


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.