user2546449
user2546449

Reputation: 21

Java using hibernate

i was trying a basic program in java using hibernate... but im getting the following error description

WARN: HHH000277: Could not bind factory to JNDI
org.hibernate.service.jndi.JndiException: Error parsing JNDI name [hiber]
    at org.hibernate.service.jndi.internal.JndiServiceImpl.parseName(JndiServiceImpl.java:92)
    at org.hibernate.service.jndi.internal.JndiServiceImpl.bind(JndiServiceImpl.java:108)
    at org.hibernate.internal.SessionFactoryRegistry.addSessionFactory(SessionFactoryRegistry.java:89)
    at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:480)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1769)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1840)
    at manageEmployee.main(manageEmployee.java:26)
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(Unknown Source)
    at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
    at javax.naming.InitialContext.getURLOrDefaultInitCtx(Unknown Source)
    at javax.naming.InitialContext.getNameParser(Unknown Source)
    at org.hibernate.service.jndi.internal.JndiServiceImpl.parseName(JndiServiceImpl.java:86)
    ... 6 more

Exception in thread "main" java.lang.ClassCastException: org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction cannot be cast to javax.transaction.Transaction
    at manageEmployee.addEmployee(manageEmployee.java:44)
    at manageEmployee.main(manageEmployee.java:34)

Upvotes: 2

Views: 7468

Answers (3)

A.Aleem11
A.Aleem11

Reputation: 1954

Check your imports statement if found this:

import javax.transaction.Transaction;

Then replace this with:

import org.hibernate.Transaction;

And remove casting from all places find where you're casting like below:

 tx = (Transaction) session.beginTransaction();

Remove

(Transaction)

to remove casting from all places.

Upvotes: 3

Dennis Kriechel
Dennis Kriechel

Reputation: 3749

This could be triggert by either there are some depending libarys of hibernate missing or u have imported some false libarys with the same name.

Upvotes: 0

Sumit Bisht
Sumit Bisht

Reputation: 1517

I fixed this by removing the name attribute from opening session factory tag in my hibernate configuration file so that it looks like the following:

<session-factory>

instead of

<session-factory name="">

Upvotes: 7

Related Questions