Category Archives: Hibernate

Hibernate tutorial: One to one and Many to many mapping annotation

This post about hibernate tutorial i will show how to implement many to many and one to one mapping in hibernate using JPA annotation. We will using source code from previous post Hibernate tutorial: one-to-many mapping annotation as code base for this article.
Continue reading Hibernate tutorial: One to one and Many to many mapping annotation

Hibernate – WARN: HHH000374: Could not unbind factory from JNDI

Symptom

When run application with hibernate outside JEE environment we get follow warning

WARN: HHH000277: Could not bind factory to JNDI
org.hibernate.engine.jndi.JndiException: Error parsing JNDI name []
	at org.hibernate.engine.jndi.internal.JndiServiceImpl.parseName(JndiServiceImpl.java:141)
	at org.hibernate.engine.jndi.internal.JndiServiceImpl.bind(JndiServiceImpl.java:157)
	at org.hibernate.internal.SessionFactoryRegistry.addSessionFactory(SessionFactoryRegistry.java:103)
	at org.hibernate.internal.SessionFactoryImpl.(SessionFactoryImpl.java:497)
	at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1857)
....
Caused by: javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:  java.naming.factory.initial
	at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:662)
	at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:307)
	at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:344)
	at javax.naming.InitialContext.getNameParser(InitialContext.java:499)
	at org.hibernate.engine.jndi.internal.JndiServiceImpl.parseName(JndiServiceImpl.java:135)
	... 7 more

Cause

The above issue occur cause you specific name on your hibernate configuration file

<hibernate-configuration>
<session-factory name="">
 ....

Solution

When run hibernate application outside JEE environment, you should remove name property from hibernate configuration file as below

<hibernate-configuration>
<session-factory >
  ...

Hibernate tutorial: How to install hibernate/jboss tool for eclipse

Hibernate tool is a useful tool for hibernate developer to generate hibernate relate file such as xml mapping file, hibernate config files… Further more it has reverse engineering feature that allow you to generate Hibernate model class from existed database tables.
In this post i will guide you how to install that tool into eclipse to increase your productivity in hibernate application development.

1. Requirement

To install Hibernate tool you need to know what version of eclipse that you using. You can achive that by go to Help->About in Eclipse IDE

ecipse version
eclipse version

2. Install Jboss tool

In eclipse IDE go to Help->Eclipse Marketplace and navigate to Find field,
enter search text “Jboss tool”. Choose the Jboss tool match with your ecipse version and install.

install jboss tool
install jboss tool

HibernateException: null index column for collection

1. Symtom
When access one-to-many relation with collection mapping by list. You may be get this error

Caused by: org.hibernate.HibernateException: null index column for collection: org.ow2.bonita.runtime.model.Execution.executions

at org.hibernate.persister.collection.AbstractCollectionPersister.readIndex(AbstractCollectionPersister.java:710)

at org.hibernate.collection.PersistentList.readFrom(PersistentList.java:379)

at org.hibernate.loader.Loader.readCollectionElement(Loader.java:1008)

at org.hibernate.loader.Loader.readCollectionElements(Loader.java:646)

at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:591)

at org.hibernate.loader.Loader.doQuery(Loader.java:701)

at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)

at org.hibernate.loader.Loader.loadCollection(Loader.java:1994)

at org.hibernate.loader.collection.CollectionLoader.initialize(CollectionLoader.java:36)

Continue reading HibernateException: null index column for collection