-->
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.  [ 13 posts ] 
Author Message
 Post subject: Unable to read a simple one-many relation
PostPosted: Mon Jan 02, 2006 2:23 am 
Newbie

Joined: Mon Jan 02, 2006 1:40 am
Posts: 9
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hi,

I am trying with a very simple one-to-many relationship. When I am storing the objects, there are no problems. But when I am trying to read out the collection, it says invalid descriptor index. Please help.

Regards,


Hibernate version:
hibernate-3.1rc2

Mapping documents:
<?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="Parent">
<id name="id">
<generator class="identity"/>
</id>
<set name="children">
<key column="parent_id"/>
<one-to-many class="Child"/>
</set>
</class>

<class name="Child">
<id name="id">
<generator class="identity"/>
</id>
<property name="name"/>
</class>

</hibernate-mapping>

Code between sessionFactory.openSession() and session.close():
The Parent class:

public class Parent
{
private Long id ;
private Set children;

Parent(){}

public Long getId()
{
return id;
}

public void setId(Long id)
{
this.id=id;
}

public Set getChildren()
{
return children;
}

public void setChildren(Set children)
{
this.children=children;
}
}
_____________________________________________________________
The Child class:

public class Child
{
private Long id;
private String name;

Child(){}

public Long getId()
{
return id;
}

private void setId(Long id)
{
this.id=id;
}

public String getName()
{
return name;
}

public void setName(String name)
{
this.name=name;
}
}
_____________________________________________________________
The Main class:

public class PCManager
{
public static void main(String[] args)
{
PCManager mgr = new PCManager();
List lt = null;
if (args[0].equals("store"))
{
mgr.createAndStoreParent(new HashSet(3));
}

else if (args[0].equals("list"))
{
mgr.listEvents();
}

HibernateUtil.getSessionFactory().close();
}

private void createAndStoreParent(HashSet s)
{
HibernateUtil.getSessionFactory().getCurrentSession().beginTransaction();

Parent p1 = new Parent();
int size = 3;

for (int i=size; i>0; i--)
{
Child c = new Child();
c.setName("Child"+i);
s.add(c);
}

p1.setChildren (s);

Iterator elems = s.iterator();

do {

Child ch = (Child) elems.next();
HibernateUtil.getSessionFactory().getCurrentSession().save(ch);

}while(elems.hasNext());

HibernateUtil.getSessionFactory().getCurrentSession().save(p1);

HibernateUtil.getSessionFactory().getCurrentSession().getTransaction().commit();
}

private void listEvents()
{
HibernateUtil.getSessionFactory().getCurrentSession().beginTransaction();

Parent result = (Parent) HibernateUtil.getSessionFactory().getCurrentSession().load(Parent.class, new Long(1));

System.out.println("Id is :"+ result.getId());
Set children = result.getChildren();

Iterator elems = children.iterator();

do {

Child ch = (Child) elems.next();

System.out.println("Child Name"+ ch.getName());

}while(elems.hasNext());



HibernateUtil.getSessionFactory().getCurrentSession().getTransaction().commit();

}
}
Full stack trace of any exception that occurs:
When I run with "hbm2ddl.auto" property as validate and trying to list the contents, I get the following out put.

C:\Documents and Settings\mirza\Desktop\hibernate-3.1rc2\MyHibernate>ant run -Da
ction=list
Buildfile: build.xml

clean:
[delete] Deleting directory C:\Documents and Settings\mirza\Desktop\hibernate
-3.1rc2\MyHibernate\bin
[mkdir] Created dir: C:\Documents and Settings\mirza\Desktop\hibernate-3.1rc
2\MyHibernate\bin

copy-resources:
[copy] Copying 4 files to C:\Documents and Settings\mirza\Desktop\hibernate
-3.1rc2\MyHibernate\bin

compile:
[javac] Compiling 5 source files to C:\Documents and Settings\mirza\Desktop\
hibernate-3.1rc2\MyHibernate\bin

run:
[java] 09:09:23,433 INFO Environment:474 - Hibernate 3.1 rc2
[java] 09:09:23,449 INFO Environment:489 - loaded properties from resource
hibernate.properties: {hibernate.cglib.use_reflection_optimizer=true, hibernate
.cache.provider_class=org.hibernate.cache.HashtableCacheProvider, hibernate.dial
ect=org.hibernate.dialect.SQLServerDialect, hibernate.max_fetch_depth=1, hiberna
te.jdbc.use_streams_for_binary=true, hibernate.format_sql=true, hibernate.query.
substitutions=yes 'Y', no 'N', hibernate.proxool.pool_alias=pool1, hibernate.cac
he.region_prefix=hibernate.test, hibernate.jdbc.batch_versioned_data=true, hiber
nate.connection.pool_size=1}
[java] 09:09:23,465 INFO Environment:519 - using java.io streams to persis
t binary types
[java] 09:09:23,465 INFO Environment:520 - using CGLIB reflection optimize
r
[java] 09:09:23,481 INFO Environment:550 - using JDK 1.4 java.sql.Timestam
p handling
[java] 09:09:23,559 INFO Configuration:1257 - configuring from resource: /
hibernate.cfg.xml
[java] 09:09:23,559 INFO Configuration:1234 - Configuration resource: /hib
ernate.cfg.xml
[java] 09:09:23,872 INFO Configuration:460 - Reading mappings from resourc
e: PCMapping.hbm.xml
[java] 09:09:24,013 INFO HbmBinder:266 - Mapping class: Parent -> Parent
[java] 09:09:24,045 INFO HbmBinder:266 - Mapping class: Child -> Child
[java] 09:09:24,045 INFO Configuration:1368 - Configured SessionFactory: n
ull
[java] 09:09:24,061 INFO Configuration:1014 - processing extends queue
[java] 09:09:24,061 INFO Configuration:1018 - processing collection mappin
gs
[java] 09:09:24,061 INFO HbmBinder:2233 - Mapping collection: Parent.child
ren -> Child
[java] 09:09:24,076 INFO Configuration:1027 - processing association prope
rty references
[java] 09:09:24,076 INFO Configuration:1049 - processing foreign key const
raints
[java] 09:09:24,155 INFO DriverManagerConnectionProvider:41 - Using Hibern
ate built-in connection pool (not for production use!)
[java] 09:09:24,170 INFO DriverManagerConnectionProvider:42 - Hibernate co
nnection pool size: 1
[java] 09:09:24,170 INFO DriverManagerConnectionProvider:45 - autocommit m
ode: false
[java] 09:09:24,170 INFO DriverManagerConnectionProvider:80 - using driver
: sun.jdbc.odbc.JdbcOdbcDriver at URL: jdbc:odbc:MySQL
[java] 09:09:24,170 INFO DriverManagerConnectionProvider:86 - connection p
roperties: {}
[java] 09:09:24,264 INFO SettingsFactory:77 - RDBMS: Microsoft SQL Server,
version: 08.00.0194
[java] 09:09:24,264 INFO SettingsFactory:78 - JDBC driver: JDBC-ODBC Bridg
e (SQLSRV32.DLL), version: 2.0001 (03.85.1117)
[java] 09:09:24,296 INFO Dialect:100 - Using dialect: org.hibernate.dialec
t.SQLServerDialect
[java] 09:09:24,311 INFO TransactionFactoryFactory:31 - Using default tran
saction strategy (direct JDBC transactions)
[java] 09:09:24,327 INFO TransactionManagerLookupFactory:33 - No Transacti
onManagerLookup configured (in JTA environment, use of read-write or transaction
al second-level cache is not recommended)
[java] 09:09:24,327 INFO SettingsFactory:125 - Automatic flush during befo
reCompletion(): disabled
[java] 09:09:24,327 INFO SettingsFactory:129 - Automatic session close at
end of transaction: disabled
[java] 09:09:24,343 INFO SettingsFactory:144 - Scrollable result sets: ena
bled
[java] 09:09:24,343 INFO SettingsFactory:152 - JDBC3 getGeneratedKeys(): d
isabled
[java] 09:09:24,343 INFO SettingsFactory:160 - Connection release mode: au
to
[java] 09:09:24,358 INFO SettingsFactory:184 - Maximum outer join fetch de
pth: 1
[java] 09:09:24,358 INFO SettingsFactory:187 - Default batch fetch size: 1

[java] 09:09:24,358 INFO SettingsFactory:191 - Generate SQL with comments:
disabled
[java] 09:09:24,358 INFO SettingsFactory:195 - Order SQL updates by primar
y key: disabled
[java] 09:09:24,358 INFO SettingsFactory:338 - Query translator: org.hiber
nate.hql.ast.ASTQueryTranslatorFactory
[java] 09:09:24,374 INFO ASTQueryTranslatorFactory:21 - Using ASTQueryTran
slatorFactory
[java] 09:09:24,374 INFO SettingsFactory:203 - Query language substitution
s: {no='N', yes='Y'}
[java] 09:09:24,374 INFO SettingsFactory:209 - Second-level cache: enabled

[java] 09:09:24,374 INFO SettingsFactory:213 - Query cache: disabled
[java] 09:09:24,374 INFO SettingsFactory:325 - Cache provider: org.hiberna
te.cache.HashtableCacheProvider
[java] 09:09:24,374 INFO SettingsFactory:228 - Optimize cache for minimal
puts: disabled
[java] 09:09:24,374 INFO SettingsFactory:233 - Cache region prefix: hibern
ate.test
[java] 09:09:24,405 INFO SettingsFactory:237 - Structured second-level cac
he entries: disabled
[java] 09:09:24,437 INFO SettingsFactory:257 - Echoing all SQL to stdout
[java] 09:09:24,452 INFO SettingsFactory:264 - Statistics: disabled
[java] 09:09:24,452 INFO SettingsFactory:268 - Deleted entity synthetic id
entifier rollback: disabled
[java] 09:09:24,452 INFO SettingsFactory:283 - Default entity-mode: POJO
[java] 09:09:24,593 INFO SessionFactoryImpl:155 - building session factory

[java] 09:09:24,938 INFO SessionFactoryObjectFactory:82 - Not binding fact
ory to JNDI, no JNDI name configured
[java] 09:09:24,954 INFO SchemaValidator:99 - Running schema validator
[java] 09:09:24,954 INFO SchemaValidator:107 - fetching database metadata
[java] 09:09:24,954 INFO Configuration:1014 - processing extends queue
[java] 09:09:24,954 INFO Configuration:1018 - processing collection mappin
gs
[java] 09:09:24,954 INFO Configuration:1027 - processing association prope
rty references
[java] 09:09:24,954 INFO Configuration:1049 - processing foreign key const
raints
[java] 09:09:24,985 WARN JDBCExceptionReporter:71 - SQL Error: 0, SQLState
: S1002
[java] 09:09:24,985 ERROR JDBCExceptionReporter:72 - [Microsoft][ODBC SQL S
erver Driver]Invalid Descriptor Index
[java] 09:09:25,001 ERROR SchemaValidator:129 - Error closing connection
[java] java.sql.SQLException: [Microsoft][ODBC SQL Server Driver]Invalid transaction state
[java] Initial SessionFactory creation failed.org.hibernate.exception.Gener
icJDBCException: could not get table metadata: Child
[java] java.lang.ExceptionInInitializerError
[java] at HibernateUtil.<clinit>(Unknown Source)
[java] at PCManager.listEvents(Unknown Source)
[java] at PCManager.main(Unknown Source)
[java] Caused by: org.hibernate.exception.GenericJDBCException: could not g
et table metadata: Child
[java] at org.hibernate.exception.SQLStateConverter.handledNonSpecificE
xception(SQLStateConverter.java:91)
[java] at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6879)

[java] at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7036)
[java] at sun.jdbc.odbc.JdbcOdbc.SQLDisconnect(JdbcOdbc.java:2988)
[java] at sun.jdbc.odbc.JdbcOdbcDriver.disconnect(JdbcOdbcDriver.java:9
80)
[java] at sun.jdbc.odbc.JdbcOdbcConnection.close(JdbcOdbcConnection.jav
a:739)
[java] at org.hibernate.tool.hbm2ddl.SchemaValidator.validate(SchemaVal
idator.java:125)
[java] at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryIm
pl.java:299)
[java] at org.hibernate.cfg.Configuration.buildSessionFactory(Configura
tion.java:1145)
[java] at HibernateUtil.<clinit>(Unknown Source)
[java] at org.hibernate.exception.SQLStateConverter.convert(SQLStateCon
verter.java:79)
[java] at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExcep
tionHelper.java:43)
[java] at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExcep
tionHelper.java:29)
[java] at org.hibernate.tool.hbm2ddl.DatabaseMetadata.getTableMetadata(
DatabaseMetadata.java:100)
[java] at org.hibernate.cfg.Configuration.validateSchema(Configuration.
java:946)
[java] at org.hibernate.tool.hbm2ddl.SchemaValidator.validate(SchemaVal
idator.java:116)
[java] at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryIm
pl.java:299)
[java] at org.hibernate.cfg.Configuration.buildSessionFactory(Configura
tion.java:1145)
[java] ... 3 more
[java] Caused by: java.sql.SQLException: [Microsoft][ODBC SQL Server Driver
]Invalid Descriptor Index
[java] at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6879)

[java] at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7036)
[java] at sun.jdbc.odbc.JdbcOdbc.SQLGetDataString(JdbcOdbc.java:3862)
[java] at sun.jdbc.odbc.JdbcOdbcResultSet.getDataString(JdbcOdbcResultS
et.java:5561)
[java] at sun.jdbc.odbc.JdbcOdbcResultSet.getString(JdbcOdbcResultSet.j
ava:338)
[java] at sun.jdbc.odbc.JdbcOdbcResultSet.getString(JdbcOdbcResultSet.j
ava:395)
[java] at PCManager.listEvents(Unknown Source)
[java] at PCManager.main(Unknown Source)
[java] at org.hibernate.tool.hbm2ddl.TableMetadata.<init>(TableMetadata
.java:30)
[java] at org.hibernate.tool.hbm2ddl.DatabaseMetadata.getTableMetadata(
DatabaseMetadata.java:85)
[java] ... 7 more
[java] Exception in thread "main"
[java] Java Result: 1

BUILD SUCCESSFUL
Total time: 4 seconds

Name and version of the database you are using:
Microsoft SQLServer2000

The generated SQL (show_sql=true):
When the program is run with "hbm2ddl.auto" property as create, I get the following output.

C:\Documents and Settings\mirza\Desktop\hibernate-3.1rc2\MyHibernate>ant run -Daction=store
Buildfile: build.xml

clean:
[delete] Deleting directory C:\Documents and Settings\mirza\Desktop\hibernate
-3.1rc2\MyHibernate\bin
[mkdir] Created dir: C:\Documents and Settings\mirza\Desktop\hibernate-3.1rc
2\MyHibernate\bin

copy-resources:
[copy] Copying 4 files to C:\Documents and Settings\mirza\Desktop\hibernate
-3.1rc2\MyHibernate\bin

compile:
[javac] Compiling 5 source files to C:\Documents and Settings\mirza\Desktop\
hibernate-3.1rc2\MyHibernate\bin

run:
[java] 09:12:54,820 INFO Environment:474 - Hibernate 3.1 rc2
[java] 09:12:54,836 INFO Environment:489 - loaded properties from resource
hibernate.properties: {hibernate.cglib.use_reflection_optimizer=true, hibernate
.cache.provider_class=org.hibernate.cache.HashtableCacheProvider, hibernate.dial
ect=org.hibernate.dialect.SQLServerDialect, hibernate.max_fetch_depth=1, hiberna
te.jdbc.use_streams_for_binary=true, hibernate.format_sql=true, hibernate.query.
substitutions=yes 'Y', no 'N', hibernate.proxool.pool_alias=pool1, hibernate.cac
he.region_prefix=hibernate.test, hibernate.jdbc.batch_versioned_data=true, hiber
nate.connection.pool_size=1}
[java] 09:12:54,852 INFO Environment:519 - using java.io streams to persis
t binary types
[java] 09:12:54,852 INFO Environment:520 - using CGLIB reflection optimize
r
[java] 09:12:54,867 INFO Environment:550 - using JDK 1.4 java.sql.Timestam
p handling
[java] 09:12:54,946 INFO Configuration:1257 - configuring from resource: /
hibernate.cfg.xml
[java] 09:12:54,946 INFO Configuration:1234 - Configuration resource: /hib
ernate.cfg.xml
[java] 09:12:55,259 INFO Configuration:460 - Reading mappings from resourc
e: PCMapping.hbm.xml
[java] 09:12:55,400 INFO HbmBinder:266 - Mapping class: Parent -> Parent
[java] 09:12:55,447 INFO HbmBinder:266 - Mapping class: Child -> Child
[java] 09:12:55,447 INFO Configuration:1368 - Configured SessionFactory: n
ull
[java] 09:12:55,447 INFO Configuration:1014 - processing extends queue
[java] 09:12:55,447 INFO Configuration:1018 - processing collection mappin
gs
[java] 09:12:55,447 INFO HbmBinder:2233 - Mapping collection: Parent.child
ren -> Child
[java] 09:12:55,463 INFO Configuration:1027 - processing association prope
rty references
[java] 09:12:55,479 INFO Configuration:1049 - processing foreign key const
raints
[java] 09:12:55,557 INFO DriverManagerConnectionProvider:41 - Using Hibern
ate built-in connection pool (not for production use!)
[java] 09:12:55,557 INFO DriverManagerConnectionProvider:42 - Hibernate co
nnection pool size: 1
[java] 09:12:55,557 INFO DriverManagerConnectionProvider:45 - autocommit m
ode: false
[java] 09:12:55,573 INFO DriverManagerConnectionProvider:80 - using driver
: sun.jdbc.odbc.JdbcOdbcDriver at URL: jdbc:odbc:MySQL
[java] 09:12:55,573 INFO DriverManagerConnectionProvider:86 - connection p
roperties: {}
[java] 09:12:55,651 INFO SettingsFactory:77 - RDBMS: Microsoft SQL Server,
version: 08.00.0194
[java] 09:12:55,667 INFO SettingsFactory:78 - JDBC driver: JDBC-ODBC Bridg
e (SQLSRV32.DLL), version: 2.0001 (03.85.1117)
[java] 09:12:55,682 INFO Dialect:100 - Using dialect: org.hibernate.dialec
t.SQLServerDialect
[java] 09:12:55,698 INFO TransactionFactoryFactory:31 - Using default tran
saction strategy (direct JDBC transactions)
[java] 09:12:55,714 INFO TransactionManagerLookupFactory:33 - No Transacti
onManagerLookup configured (in JTA environment, use of read-write or transaction
al second-level cache is not recommended)
[java] 09:12:55,714 INFO SettingsFactory:125 - Automatic flush during befo
reCompletion(): disabled
[java] 09:12:55,714 INFO SettingsFactory:129 - Automatic session close at
end of transaction: disabled
[java] 09:12:55,729 INFO SettingsFactory:144 - Scrollable result sets: ena
bled
[java] 09:12:55,729 INFO SettingsFactory:152 - JDBC3 getGeneratedKeys(): d
isabled
[java] 09:12:55,745 INFO SettingsFactory:160 - Connection release mode: au
to
[java] 09:12:55,745 INFO SettingsFactory:184 - Maximum outer join fetch de
pth: 1
[java] 09:12:55,745 INFO SettingsFactory:187 - Default batch fetch size: 1

[java] 09:12:55,745 INFO SettingsFactory:191 - Generate SQL with comments:
disabled
[java] 09:12:55,745 INFO SettingsFactory:195 - Order SQL updates by primar
y key: disabled
[java] 09:12:55,745 INFO SettingsFactory:338 - Query translator: org.hiber
nate.hql.ast.ASTQueryTranslatorFactory
[java] 09:12:55,777 INFO ASTQueryTranslatorFactory:21 - Using ASTQueryTran
slatorFactory
[java] 09:12:55,792 INFO SettingsFactory:203 - Query language substitution
s: {no='N', yes='Y'}
[java] 09:12:55,792 INFO SettingsFactory:209 - Second-level cache: enabled

[java] 09:12:55,792 INFO SettingsFactory:213 - Query cache: disabled
[java] 09:12:55,792 INFO SettingsFactory:325 - Cache provider: org.hiberna
te.cache.HashtableCacheProvider
[java] 09:12:55,808 INFO SettingsFactory:228 - Optimize cache for minimal
puts: disabled
[java] 09:12:55,808 INFO SettingsFactory:233 - Cache region prefix: hibern
ate.test
[java] 09:12:55,808 INFO SettingsFactory:237 - Structured second-level cac
he entries: disabled
[java] 09:12:55,839 INFO SettingsFactory:257 - Echoing all SQL to stdout
[java] 09:12:55,839 INFO SettingsFactory:264 - Statistics: disabled
[java] 09:12:55,839 INFO SettingsFactory:268 - Deleted entity synthetic id
entifier rollback: disabled
[java] 09:12:55,839 INFO SettingsFactory:283 - Default entity-mode: POJO
[java] 09:12:55,980 INFO SessionFactoryImpl:155 - building session factory

[java] 09:12:56,325 INFO SessionFactoryObjectFactory:82 - Not binding fact
ory to JNDI, no JNDI name configured
[java] 09:12:56,341 INFO Configuration:1014 - processing extends queue
[java] 09:12:56,341 INFO Configuration:1018 - processing collection mappin
gs
[java] 09:12:56,341 INFO Configuration:1027 - processing association prope
rty references
[java] 09:12:56,341 INFO Configuration:1049 - processing foreign key const
raints
[java] 09:12:56,356 INFO Configuration:1014 - processing extends queue
[java] 09:12:56,356 INFO Configuration:1018 - processing collection mappin
gs
[java] 09:12:56,356 INFO Configuration:1027 - processing association prope
rty references
[java] 09:12:56,372 INFO Configuration:1049 - processing foreign key const
raints
[java] 09:12:56,372 INFO SchemaExport:153 - Running hbm2ddl schema export
[java] 09:12:56,388 DEBUG SchemaExport:171 - import file not found: /import
.sql
[java] 09:12:56,388 INFO SchemaExport:180 - exporting generated schema to
database
[java] 09:12:56,403 DEBUG SchemaExport:283 -
[java] alter table Child
[java] drop constraint FK3E104FC976A59A
[java] 09:12:56,466 DEBUG SchemaExport:283 -
[java] drop table Child
[java] 09:12:56,544 DEBUG SchemaExport:283 -
[java] drop table Parent
[java] 09:12:56,654 DEBUG SchemaExport:283 -
[java] create table Child (
[java] id numeric(19,0) identity not null,
[java] name varchar(255) null,
[java] parent_id numeric(19,0) null,
[java] primary key (id)
[java] )
[java] 09:12:56,779 DEBUG SchemaExport:283 -
[java] create table Parent (
[java] id numeric(19,0) identity not null,
[java] primary key (id)
[java] )
[java] 09:12:56,873 DEBUG SchemaExport:283 -
[java] alter table Child
[java] add constraint FK3E104FC976A59A
[java] foreign key (parent_id)
[java] references Parent
[java] 09:12:56,952 INFO SchemaExport:200 - schema export complete
[java] 09:12:56,952 WARN JDBCExceptionReporter:48 - SQL Warning: 5701, SQL
State: 01000
[java] 09:12:56,952 WARN JDBCExceptionReporter:49 - [Microsoft][ODBC SQL S
erver Driver][SQL Server]Changed database context to 'master'.
[java] 09:12:56,952 WARN JDBCExceptionReporter:48 - SQL Warning: 5703, SQL
State: 01000
[java] 09:12:56,952 WARN JDBCExceptionReporter:49 - [Microsoft][ODBC SQL S
erver Driver][SQL Server]Changed language setting to us_english.
[java] 09:12:56,983 INFO SessionFactoryImpl:432 - Checking 0 named queries

[java] Hibernate:
[java] insert
[java] into
[java] Child
[java] (name)
[java] values
[java] (?) select
[java] scope_identity()
[java] Hibernate:
[java] insert
[java] into
[java] Child
[java] (name)
[java] values
[java] (?) select
[java] scope_identity()
[java] Hibernate:
[java] insert
[java] into
[java] Child
[java] (name)
[java] values
[java] (?) select
[java] scope_identity()
[java] Hibernate:
[java] insert
[java] into
[java] Parent
[java] default
[java] values
[java] select
[java] scope_identity()
[java] Hibernate:
[java] update
[java] Child
[java] set
[java] parent_id=?
[java] where
[java] id=?
[java] Hibernate:
[java] update
[java] Child
[java] set
[java] parent_id=?
[java] where
[java] id=?
[java] Hibernate:
[java] update
[java] Child
[java] set
[java] parent_id=?
[java] where
[java] id=?
[java] 09:12:57,390 INFO SessionFactoryImpl:831 - closing
[java] 09:12:57,390 INFO DriverManagerConnectionProvider:147 - cleaning up
connection pool: jdbc:odbc:MySQL

BUILD SUCCESSFUL
Total time: 5 seconds
Debug level Hibernate log excerpt:
Included in the above description.

_________________
Mirza M.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 02, 2006 5:17 am 
Regular
Regular

Joined: Wed Jun 29, 2005 11:14 pm
Posts: 119
Location: København
This is actually an error in the driver class:

"This exception is usually thrown when retrieving a LONGVARCHAR or LONGVARBINARY column using the getXXXStream() method (column size > DefMaxFieldSize of idss.ini). This exception can be avoided by re-ordering your SELECT statement so that the long column is place at the end of the select list."

Therefore, I suggest investigating a new driver as it's pretty mandatory to be able to load objects - unless you can get around by excecuting only selects? - unlikely...

What DB you using?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 02, 2006 5:19 am 
Regular
Regular

Joined: Wed Jun 29, 2005 11:14 pm
Posts: 119
Location: København
I see you are using the jdbc-odbc driver -

try the com.mysql.jdbc.Driver


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 02, 2006 5:22 am 
Regular
Regular

Joined: Wed Jun 29, 2005 11:14 pm
Posts: 119
Location: København
Errr - confused - the dialect is SQLServerDialect but is bound to jndi jdbc:odbc:MySQL....

So maybe best not to use the mysql driver for SQLServer - my mistake. But is there another one you can use?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 02, 2006 5:33 am 
Newbie

Joined: Mon Jan 02, 2006 1:40 am
Posts: 9
Thanks for your reply timrobertson100,

But this MySQL is not the database "mysql" but simple the DSN (Data Source Name) I created for SQLServer connection in the Windows Control Panel (ODBC Connections).

_________________
Mirza M.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 02, 2006 5:47 am 
Regular
Regular

Joined: Wed Jun 29, 2005 11:14 pm
Posts: 119
Location: København
Yeah - I saw that and got confused. What DB is underneath then? Looks like you are using the SQLServer Dialect but an odbc bridge driver. Can you not get a direct jdbc driver for sqlserver?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 02, 2006 5:49 am 
Regular
Regular

Joined: Wed Jun 29, 2005 11:14 pm
Posts: 119
Location: København
E.g. http://www.microsoft.com/downloads/deta ... layLang=en


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 02, 2006 7:02 am 
Newbie

Joined: Mon Jan 02, 2006 1:40 am
Posts: 9
I tried using other drivers, for example, I tried with jTDS JDBC Driver, just yesterday. But I was not able to use it as I found "Connection Refused" problem. :(

I tired some other drivers also but with the same problem, "Connection Refused". I checked the port no. of SQLServer and it was using same 1433, the default one. The SQL Server Enterprise Manager also works fine. But trying with some other driver always giving error of connection refusal. Thats the reason I switched back to ODBC.

If you could guide me to overcome the "Connection Refused" problem also, I would be highly grateful.

Thanks again.

_________________
Mirza M.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 02, 2006 7:56 am 
Regular
Regular

Joined: Wed Jun 29, 2005 11:14 pm
Posts: 119
Location: København
Please post your hibernate.cfg.xml

Below is a working mysql config, and I've had a stab at doing one for you.
This assumes you've used the driver from microsoft that I posted above - I'd say that was a good driver to start with.

A JDBC driver will be much better than an ODBC bridge, so worth getting this working I think.

This is my mysql one:

Code:
<?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 name="SessionFactory">
        <property name="hibernate.connection.driver_class">org.gjt.mm.mysql.Driver</property>
        <property name="hibernate.connection.password">password</property>
        <property name="hibernate.connection.url">jdbc:mysql://localhost/portal2</property>
        <property name="hibernate.connection.username">root</property>
        <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
    </session-factory>
</hibernate-configuration>


And yours will be something like:

Code:
<?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 name="SessionFactory">
        <property name="hibernate.connection.driver_class">com.microsoft.jdbc.sqlserver.SQLServerDriver</property>
        <property name="hibernate.connection.password">password</property>
        <property name="hibernate.connection.url">jdbc:microsoft:sqlserver://localhost:1433</property>
        <property name="hibernate.connection.username">root</property>
        <property name="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</property>
    </session-factory>
</hibernate-configuration>


You'll need to put the driver on the classpath of course.

Of course this is using the built in pooling which will need to be replaced by DBCP (or a JNDI lookup for a server managed pool) but for now, let's rety and get it running stand alone.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 03, 2006 2:16 am 
Newbie

Joined: Mon Jan 02, 2006 1:40 am
Posts: 9
Now when I tried with the Microsoft driver you suggested, I get the following output (Error Establishing Socket). My hibernate.cfg file is as follows.

<?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 name="SessionFactory">
<property name="hibernate.connection.driver_class">com.microsoft.jdbc.sqlserver.SQLServerDriver</property>
<property name="hibernate.connection.url">jdbc:microsoft:sqlserver://localhost:1433</property>
<property name="hibernate.connection.username">sa</property>
<property name="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</property>
</session-factory>
</hibernate-configuration>

There is no password for the user "sa", and SQLServer is installed on my local machine and the TCP/IP port it is using is 1433. The three .jar files msbase, mssqlserver and msutil are already placed with the lib directory of my program.

The output got is below:



Buildfile: build.xml

clean:
[delete] Deleting directory C:\Documents and Settings\mirza\Desktop\hibernate
-3.1rc2\MyHibernate\bin
[mkdir] Created dir: C:\Documents and Settings\mirza\Desktop\hibernate-3.1rc
2\MyHibernate\bin

copy-resources:
[copy] Copying 4 files to C:\Documents and Settings\mirza\Desktop\hibernate
-3.1rc2\MyHibernate\bin

compile:
[javac] Compiling 5 source files to C:\Documents and Settings\mirza\Desktop\
hibernate-3.1rc2\MyHibernate\bin

run:
[java] 09:04:29,248 INFO Environment:474 - Hibernate 3.1 rc2
[java] 09:04:29,263 INFO Environment:489 - loaded properties from resource
hibernate.properties: {hibernate.cglib.use_reflection_optimizer=true, hibernate
.cache.provider_class=org.hibernate.cache.HashtableCacheProvider, hibernate.dial
ect=org.hibernate.dialect.SQLServerDialect, hibernate.max_fetch_depth=1, hiberna
te.jdbc.use_streams_for_binary=true, hibernate.format_sql=true, hibernate.query.
substitutions=yes 'Y', no 'N', hibernate.proxool.pool_alias=pool1, hibernate.cac
he.region_prefix=hibernate.test, hibernate.jdbc.batch_versioned_data=true, hiber
nate.connection.pool_size=1}
[java] 09:04:29,263 INFO Environment:519 - using java.io streams to persis
t binary types
[java] 09:04:29,263 INFO Environment:520 - using CGLIB reflection optimize
r
[java] 09:04:29,279 INFO Environment:550 - using JDK 1.4 java.sql.Timestam
p handling
[java] 09:04:29,357 INFO Configuration:1257 - configuring from resource: /
hibernate.cfg.xml
[java] 09:04:29,373 INFO Configuration:1234 - Configuration resource: /hib
ernate.cfg.xml
[java] 09:04:29,685 INFO Configuration:1368 - Configured SessionFactory: S
essionFactory
[java] 09:04:29,685 INFO Configuration:1014 - processing extends queue
[java] 09:04:29,685 INFO Configuration:1018 - processing collection mappin
gs
[java] 09:04:29,701 INFO Configuration:1027 - processing association prope
rty references
[java] 09:04:29,701 INFO Configuration:1049 - processing foreign key const
raints
[java] 09:04:29,717 INFO DriverManagerConnectionProvider:41 - Using Hibern
ate built-in connection pool (not for production use!)
[java] 09:04:29,717 INFO DriverManagerConnectionProvider:42 - Hibernate co
nnection pool size: 1
[java] 09:04:29,732 INFO DriverManagerConnectionProvider:45 - autocommit m
ode: false
[java] 09:04:29,748 INFO DriverManagerConnectionProvider:80 - using driver
: com.microsoft.jdbc.sqlserver.SQLServerDriver at URL: jdbc:microsoft:sqlserver:
//localhost:1433
[java] 09:04:29,748 INFO DriverManagerConnectionProvider:86 - connection p
roperties: {user=sa}
[java] 09:04:30,857 WARN SettingsFactory:103 - Could not obtain connection
metadata
[java] java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Er
ror establishing socket.
[java] at com.microsoft.jdbc.base.BaseExceptions.createException(Unknow
n Source)
[java] at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown S
ource)
[java] at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown S
ource)
[java] at com.microsoft.jdbc.sqlserver.tds.TDSConnection.<init>(Unknown
Source)
[java] at com.microsoft.jdbc.sqlserver.SQLServerImplConnection.open(Unk
nown Source)
[java] at com.microsoft.jdbc.base.BaseConnection.getNewImplConnection(U
nknown Source)
[java] at com.microsoft.jdbc.base.BaseConnection.open(Unknown Source)
[java] at com.microsoft.jdbc.base.BaseDriver.connect(Unknown Source)
[java] at java.sql.DriverManager.getConnection(DriverManager.java:512)
[java] at java.sql.DriverManager.getConnection(DriverManager.java:140)
[java] at org.hibernate.connection.DriverManagerConnectionProvider.getC
onnection(DriverManagerConnectionProvider.java:110)
[java] at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFacto
ry.java:72)
[java] at org.hibernate.cfg.Configuration.buildSettings(Configuration.j
ava:1823)
[java] at org.hibernate.cfg.Configuration.buildSessionFactory(Configura
tion.java:1143)
[java] at HibernateUtil.<clinit>(Unknown Source)
[java] at PCManager.createAndStoreParent(Unknown Source)
[java] at PCManager.main(Unknown Source)
[java] 09:04:30,967 INFO Dialect:100 - Using dialect: org.hibernate.dialec
t.SQLServerDialect
[java] 09:04:31,013 INFO TransactionFactoryFactory:31 - Using default tran
saction strategy (direct JDBC transactions)
[java] 09:04:31,029 INFO TransactionManagerLookupFactory:33 - No Transacti
onManagerLookup configured (in JTA environment, use of read-write or transaction
al second-level cache is not recommended)
[java] 09:04:31,029 INFO SettingsFactory:125 - Automatic flush during befo
reCompletion(): disabled
[java] 09:04:31,029 INFO SettingsFactory:129 - Automatic session close at
end of transaction: disabled
[java] 09:04:31,045 INFO SettingsFactory:144 - Scrollable result sets: dis
abled
[java] 09:04:31,045 INFO SettingsFactory:152 - JDBC3 getGeneratedKeys(): d
isabled
[java] 09:04:31,045 INFO SettingsFactory:160 - Connection release mode: au
to
[java] 09:04:31,060 INFO SettingsFactory:184 - Maximum outer join fetch de
pth: 1
[java] 09:04:31,060 INFO SettingsFactory:187 - Default batch fetch size: 1

[java] 09:04:31,060 INFO SettingsFactory:191 - Generate SQL with comments:
disabled
[java] 09:04:31,076 INFO SettingsFactory:195 - Order SQL updates by primar
y key: disabled
[java] 09:04:31,076 INFO SettingsFactory:338 - Query translator: org.hiber
nate.hql.ast.ASTQueryTranslatorFactory
[java] 09:04:31,092 INFO ASTQueryTranslatorFactory:21 - Using ASTQueryTran
slatorFactory
[java] 09:04:31,092 INFO SettingsFactory:203 - Query language substitution
s: {no='N', yes='Y'}
[java] 09:04:31,092 INFO SettingsFactory:209 - Second-level cache: enabled

[java] 09:04:31,092 INFO SettingsFactory:213 - Query cache: disabled
[java] 09:04:31,107 INFO SettingsFactory:325 - Cache provider: org.hiberna
te.cache.HashtableCacheProvider
[java] 09:04:31,123 INFO SettingsFactory:228 - Optimize cache for minimal
puts: disabled
[java] 09:04:31,123 INFO SettingsFactory:233 - Cache region prefix: hibern
ate.test
[java] 09:04:31,123 INFO SettingsFactory:237 - Structured second-level cac
he entries: disabled
[java] 09:04:31,139 INFO SettingsFactory:264 - Statistics: disabled
[java] 09:04:31,139 INFO SettingsFactory:268 - Deleted entity synthetic id
entifier rollback: disabled
[java] 09:04:31,154 INFO SettingsFactory:283 - Default entity-mode: POJO
[java] 09:04:31,264 INFO SessionFactoryImpl:155 - building session factory

[java] 09:04:31,279 INFO SessionFactoryObjectFactory:86 - Factory name: Se
ssionFactory
[java] 09:04:31,279 INFO NamingHelper:26 - JNDI InitialContext properties:
{}
[java] 09:04:31,310 WARN SessionFactoryObjectFactory:98 - Could not bind f
actory to JNDI
[java] javax.naming.NoInitialContextException: Need to specify class name i
n environment or system property, or as an applet parameter, or in an applicatio
n resource file: java.naming.factory.initial
[java] at javax.naming.spi.NamingManager.getInitialContext(NamingManage
r.java:640)
[java] at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.
java:243)
[java] at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialCon
text.java:280)
[java] at javax.naming.InitialContext.getNameParser(InitialContext.java
:429)
[java] at org.hibernate.util.NamingHelper.bind(NamingHelper.java:52)
[java] at org.hibernate.impl.SessionFactoryObjectFactory.addInstance(Se
ssionFactoryObjectFactory.java:90)
[java] org.hibernate.HibernateException: No CurrentSessionContext configure
d!
[java] at org.hibernate.impl.SessionFactoryImpl.getCurrentSession(Sessi
onFactoryImpl.java:602)
[java] at PCManager.createAndStoreParent(Unknown Source)
[java] at PCManager.main(Unknown Source)
[java] at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryIm
pl.java:293)
[java] at org.hibernate.cfg.Configuration.buildSessionFactory(Configura
tion.java:1145)
[java] at HibernateUtil.<clinit>(Unknown Source)
[java] at PCManager.createAndStoreParent(Unknown Source)
[java] at PCManager.main(Unknown Source)
[java] 09:04:31,310 INFO SessionFactoryImpl:432 - Checking 0 named queries

[java] Exception in thread "main"
[java] Java Result: 1

BUILD SUCCESSFUL

_________________
Mirza M.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 03, 2006 5:12 am 
Regular
Regular

Joined: Wed Jun 29, 2005 11:14 pm
Posts: 119
Location: København
This is something getting in the way of the JVM tsalking to the DB - e.g. your firewall. I googled and found that windows service pack 2 will configure the windows firewall to block port 1433- that would be the first place to start. Whatever firewall you have running, ensure that 1433 is open

Try this search - lot's of results on the exact topic
http://www.google.com/search?hl=en&q=%5 ... gle+Search

or read which has a workaround http://www.websina.com/bugzero/errors/s ... error.html

I haven't got sql server so can't really offer too much more help - but I recommend staying clear of the odbc and persevering with the jdbc driver... good luck


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 03, 2006 5:19 am 
Regular
Regular

Joined: Wed Jun 29, 2005 11:14 pm
Posts: 119
Location: København
This one has some good suggestions

http://forum.java.sun.com/thread.jspa?t ... 4&start=15


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 04, 2006 3:28 am 
Newbie

Joined: Mon Jan 02, 2006 1:40 am
Posts: 9
Hi timrobertson,

Thank you very much for the great help. I tried with Microsoft Driver for SQLServer, had to download and install the Servicepack 3a for SQLServer2000 and then.... IT GOT RUN !!! :) :)

Thanks again. I will be ever grateful to you for the excellent guidance you provided.

All the BEST.

_________________
Mirza M.


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