Subject | Text blob NullPointerException test case |
---|---|
Author | Grzegorz Kowal |
Post date | 2005-04-20T17:34:20Z |
I hope this isn't too large to post here, crashes on Windows only
(Hibernate 2.1.6).
Regards,
Grzegorz
[Test2.java] - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - -
import java.io.IOException;
import java.io.InputStream;
import java.sql.Statement;
import java.util.Iterator;
import java.util.List;
import java.util.Properties;
import org.apache.log4j.BasicConfigurator;
import net.sf.hibernate.HibernateException;
import net.sf.hibernate.Session;
import net.sf.hibernate.SessionFactory;
import net.sf.hibernate.Transaction;
import net.sf.hibernate.cfg.Configuration;
public class Test2 {
static String url =
"jdbc:firebirdsql:localhost/3050:/tmp/test.fdb?lc_ctype=WIN1250";
static String user = "********";
static String password = "********";
public static void main(String[] args) throws HibernateException,
IOException {
BasicConfigurator.configure();
InputStream in = null;
SessionFactory sf = null;
Session sess = null;
Transaction tx = null;
Statement st = null;
try {
Properties props = new Properties();
in =
Test2.class.getClassLoader().getResourceAsStream("hibernate.properties");
props.load(in);
in.close();
props.setProperty("hibernate.dialect",
"net.sf.hibernate.dialect.FirebirdDialect");
props.setProperty("hibernate.connection.driver_class",
"org.firebirdsql.jdbc.FBDriver");
props.setProperty("hibernate.connection.url", url);
props.setProperty("hibernate.connection.username", user);
props.setProperty("hibernate.connection.password", password);
Configuration cfg = new Configuration()
.setProperties(props)
.addClass(Blob.class);
sf = cfg.buildSessionFactory();
sess = sf.openSession();
tx = sess.beginTransaction();
Blob b = new Blob();
b.setBlobData("Very long text...");
sess.save(b);
tx.commit();
sess.close();
sess = sf.openSession();
tx = sess.beginTransaction();
List blobs = sess.find("from Blob");
for (Iterator iter = blobs.iterator(); iter.hasNext();) {
System.out.println((Blob) iter.next());
}
tx.commit();
} catch (HibernateException e) {
e.printStackTrace();
if (tx != null)
tx.rollback();
} finally {
if (sess != null)
sess.close();
if (sf != null)
sf.close();
}
}
}
[Blob.java] - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - -
/**
* @... table="blob_test"
*/
public class Blob {
private Long _uid;
private int _version;
private String _blobData;
/**
* @... generator-class="seqhilo"
*/
public Long getUid() {
return _uid;
}
private void setUid(Long uid) {
_uid = uid;
}
/**
* @...
*/
public int getVersion() {
return _version;
}
private void setVersion(int version) {
_version = version;
}
/**
* @... type="text"
*/
public String getBlobData() {
return _blobData;
}
public void setBlobData(String blobData) {
_blobData = blobData;
}
public String toString() {
return _blobData;
}
}
[Blob.hbm.xml] - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - -
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class
name="Blob"
table="blob_test"
dynamic-update="false"
dynamic-insert="false"
select-before-update="false"
optimistic-lock="version"
name="uid"
column="uid"
type="java.lang.Long"
<!--
To add non XDoclet generator parameters, create a file
named
hibernate-generator-params-Blob.xml
containing the additional parameters and place it in
your merge dir.
-->
</generator>
</id>
<version
name="version"
type="int"
column="version"
access="property"
unsaved-value="undefined"
/>
<property
name="blobData"
type="text"
update="true"
insert="true"
access="property"
column="blobData"
/>
<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-Blob.xml
containing the additional properties and place it in your
merge dir.
-->
</class>
</hibernate-mapping>
[hibernate.properties] - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - -
hibernate.query.substitutions true 1, false 0, yes 'Y', no 'N'
hibernate.connection.pool_size 1
hibernate.dbcp.maxActive 100
hibernate.dbcp.whenExhaustedAction 1
hibernate.dbcp.maxWait 120000
hibernate.dbcp.maxIdle 10
hibernate.dbcp.ps.maxActive 100
hibernate.dbcp.ps.whenExhaustedAction 1
hibernate.dbcp.ps.maxWait 120000
hibernate.dbcp.ps.maxIdle 10
hibernate.connection.provider_class
net.sf.hibernate.connection.DBCPConnectionProvider
hibernate.jdbc.batch_size 0
hibernate.jdbc.use_streams_for_binary true
hibernate.max_fetch_depth 1
hibernate.cglib.use_reflection_optimizer false
hibernate.cache.provider_class net.sf.ehcache.hibernate.Provider
hibernate.hbm2ddl.auto create
(Hibernate 2.1.6).
Regards,
Grzegorz
[Test2.java] - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - -
import java.io.IOException;
import java.io.InputStream;
import java.sql.Statement;
import java.util.Iterator;
import java.util.List;
import java.util.Properties;
import org.apache.log4j.BasicConfigurator;
import net.sf.hibernate.HibernateException;
import net.sf.hibernate.Session;
import net.sf.hibernate.SessionFactory;
import net.sf.hibernate.Transaction;
import net.sf.hibernate.cfg.Configuration;
public class Test2 {
static String url =
"jdbc:firebirdsql:localhost/3050:/tmp/test.fdb?lc_ctype=WIN1250";
static String user = "********";
static String password = "********";
public static void main(String[] args) throws HibernateException,
IOException {
BasicConfigurator.configure();
InputStream in = null;
SessionFactory sf = null;
Session sess = null;
Transaction tx = null;
Statement st = null;
try {
Properties props = new Properties();
in =
Test2.class.getClassLoader().getResourceAsStream("hibernate.properties");
props.load(in);
in.close();
props.setProperty("hibernate.dialect",
"net.sf.hibernate.dialect.FirebirdDialect");
props.setProperty("hibernate.connection.driver_class",
"org.firebirdsql.jdbc.FBDriver");
props.setProperty("hibernate.connection.url", url);
props.setProperty("hibernate.connection.username", user);
props.setProperty("hibernate.connection.password", password);
Configuration cfg = new Configuration()
.setProperties(props)
.addClass(Blob.class);
sf = cfg.buildSessionFactory();
sess = sf.openSession();
tx = sess.beginTransaction();
Blob b = new Blob();
b.setBlobData("Very long text...");
sess.save(b);
tx.commit();
sess.close();
sess = sf.openSession();
tx = sess.beginTransaction();
List blobs = sess.find("from Blob");
for (Iterator iter = blobs.iterator(); iter.hasNext();) {
System.out.println((Blob) iter.next());
}
tx.commit();
} catch (HibernateException e) {
e.printStackTrace();
if (tx != null)
tx.rollback();
} finally {
if (sess != null)
sess.close();
if (sf != null)
sf.close();
}
}
}
[Blob.java] - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - -
/**
* @... table="blob_test"
*/
public class Blob {
private Long _uid;
private int _version;
private String _blobData;
/**
* @... generator-class="seqhilo"
*/
public Long getUid() {
return _uid;
}
private void setUid(Long uid) {
_uid = uid;
}
/**
* @...
*/
public int getVersion() {
return _version;
}
private void setVersion(int version) {
_version = version;
}
/**
* @... type="text"
*/
public String getBlobData() {
return _blobData;
}
public void setBlobData(String blobData) {
_blobData = blobData;
}
public String toString() {
return _blobData;
}
}
[Blob.hbm.xml] - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - -
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class
name="Blob"
table="blob_test"
dynamic-update="false"
dynamic-insert="false"
select-before-update="false"
optimistic-lock="version"
><id
name="uid"
column="uid"
type="java.lang.Long"
><generator class="seqhilo">
<!--
To add non XDoclet generator parameters, create a file
named
hibernate-generator-params-Blob.xml
containing the additional parameters and place it in
your merge dir.
-->
</generator>
</id>
<version
name="version"
type="int"
column="version"
access="property"
unsaved-value="undefined"
/>
<property
name="blobData"
type="text"
update="true"
insert="true"
access="property"
column="blobData"
/>
<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-Blob.xml
containing the additional properties and place it in your
merge dir.
-->
</class>
</hibernate-mapping>
[hibernate.properties] - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - -
hibernate.query.substitutions true 1, false 0, yes 'Y', no 'N'
hibernate.connection.pool_size 1
hibernate.dbcp.maxActive 100
hibernate.dbcp.whenExhaustedAction 1
hibernate.dbcp.maxWait 120000
hibernate.dbcp.maxIdle 10
hibernate.dbcp.ps.maxActive 100
hibernate.dbcp.ps.whenExhaustedAction 1
hibernate.dbcp.ps.maxWait 120000
hibernate.dbcp.ps.maxIdle 10
hibernate.connection.provider_class
net.sf.hibernate.connection.DBCPConnectionProvider
hibernate.jdbc.batch_size 0
hibernate.jdbc.use_streams_for_binary true
hibernate.max_fetch_depth 1
hibernate.cglib.use_reflection_optimizer false
hibernate.cache.provider_class net.sf.ehcache.hibernate.Provider
hibernate.hbm2ddl.auto create