• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HibernateException: Hibernate Dialect must be explicitly set

 
san krish
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Im running a stand alone application...with a java class n xml file n an entity file. I havent merged them to any particular project. I get the below error. down the post are my source files.

Exception in thread "main" javax.persistence.PersistenceException: No Persistence provider for EntityManager named jpaSample: Provider named org.hibernate.ejb.HibernatePersistence threw unexpected exception at create EntityManagerFactory:
javax.persistence.PersistenceException
javax.persistence.PersistenceException: org.hibernate.HibernateException: Hibernate Dialect must be explicitly set
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:698)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:121)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:110)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:83)
at com.inforeliance.jpa.JpaExample.main(JpaExample.java:19)
Caused by: org.hibernate.HibernateException: Hibernate Dialect must be explicitly set
at org.hibernate.dialect.DialectFactory.determineDialect(DialectFactory.java:80)
at org.hibernate.dialect.DialectFactory.buildDialect(DialectFactory.java:62)
at org.hibernate.cfg.SettingsFactory.determineDialect(SettingsFactory.java:460)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:155)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2101)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1325)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:691)
... 4 more



at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:154)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:83)
at com.inforeliance.jpa.JpaExample.main(JpaExample.java:19)



this is wht my src looks like.
persistance.xml

<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
version="1.0"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">

<persistence-unit name="jpaSample" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>com.inforeliance.jpa.Employee</class>

<properties>
<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.connection.driver_class" value="oracle.jdbc.driver.OracleDriver"/>
<property name="hibernate.connection.password" value="rcpss"/>
<property name="hibernate.connection.url" value="jdbcracle:thin:@localhost:1521:xe"/>
<property name="hibernate.connection.username" value="rcpss"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect"/>
</properties>

</persistence-unit>

</persistence>

Main class:
package com.eee.jpa;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import javax.persistence.Persistence;
import javax.persistence.Query;

public class JpaExample {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub

EntityManagerFactory emf=Persistence.createEntityManagerFactory("jpaSample");
EntityManager em=emf.createEntityManager();
EntityTransaction entr=em.getTransaction();
try{
entr.begin();
Query query = em.createQuery("SELECT E FROM EMPLOYEE");

Employee emp = (Employee) query.getSingleResult();

System.out.print("id:"+emp.getId());
System.out.print(" name:"+emp.getName());
System.out.print(" rollnum:"+emp.getRollnum());
System.out.print(" designation:"+emp.getDesignation());

entr.commit();
}catch(Exception e)
{
entr.rollback();
}
finally{
em.close();
}

}

}

Entity file:
package com.eee.jpa;

import javax.persistence.*;

@Entity
@Table(name="employee")
public class Employee {

@Id
@Column(name="id", length=100,nullable=false)
@GeneratedValue(strategy = GenerationType.AUTO)
private int id;
@Column(name="name", length=100)
private String name;
@Column(name="rollnum", length=100)
private int rollnum;
@Column(name="designation", length=100)
private String designation;

public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}

public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}

public int getRollnum() {
return rollnum;
}
public void setRollnum(int rollnum) {
this.rollnum = rollnum;
}

public String getDesignation() {
return designation;
}
public void setDesignation(String designation) {
this.designation = designation;
}

}
 
san krish
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
anyone who knows a solution to this or have faced this...please reply. a little urgent.
 
san krish
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can someone pleas help me..
 
Paul Clapham
Sheriff
Posts: 20985
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
After a couple of minutes of googling I found a site which claims that you will get this message if the code trying to set up the database fails to get a database connection. In other words it's nothing to do with setting the dialect at all.

I'm not going to link to that site because the comments are totally disgusting spam. However I do recommend searching the web for technical problems like this. Waiting for random people to provide help shouldn't be the only thing you try. By the way my Google keywords were "Hibernate Dialect must be explicitly set".
 
san krish
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks paul. I looked at the one that you are talking about. My DB connections seems to be fine. I dont have clue whatelse would be wrong.
 
san krish
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, now that i fixed tht issue, with adding matching persistance-name n autodetection in persistance.xml file...i get this error now.

Exception in thread "main" javax.persistence.PersistenceException: No Persistence provider for EntityManager named jpaSample: Provider named org.hibernate.ejb.HibernatePersistence threw unexpected exception at create EntityManagerFactory:
java.lang.AbstractMethodError
java.lang.AbstractMethodError: org.slf4j.impl.Log4jLoggerAdapter.isTraceEnabled()Z
at org.hibernate.type.NullableType.<clinit>(NullableType.java:59)
at org.hibernate.Hibernate.<clinit>(Hibernate.java:103)
at org.hibernate.type.TypeFactory.<clinit>(TypeFactory.java:69)
at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:283)
at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:276)
at org.hibernate.mapping.Property.isValid(Property.java:207)
at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:458)
at org.hibernate.mapping.RootClass.validate(RootClass.java:215)
at org.hibernate.cfg.Configuration.validate(Configuration.java:1135)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1320)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:691)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:121)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:110)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:83)
at com.inforeliance.jpa.JpaExample.main(JpaExample.java:19)



at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:154)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:83)
at com.inforeliance.jpa.JpaExample.main(JpaExample.java:19)
 
san krish
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
im getting this exception now


Exception in thread "main" java.lang.NoSuchMethodError: org.hibernate.event.PreInsertEvent.getSource()Lorg/hibernate/engine/SessionImplementor;
at org.hibernate.validator.event.ValidateEventListener.onPreInsert(ValidateEventListener.java:156)
at org.hibernate.action.EntityInsertAction.preInsert(EntityInsertAction.java:178)
at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:72)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:279)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:263)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:167)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1027)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:365)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:137)
at org.hibernate.ejb.TransactionImpl.commit(TransactionImpl.java:53)
at com.inforeliance.jpa.JpaExample.main(JpaExample.java:39)
 
Will Zelan
Ranch Hand
Posts: 56
Flex Python Windows Vista
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ;
Paul Clapham is right . this is to deal with connection to DB , instead of setting some diallect.
When I initiate my session factory through
factory = new Configuration().configure().buildSessionFactory();
it works good. so need to check with your
Persistence.createEntityManagerFactory("jpaSample"); Focus only on the connectivity.

Thanks:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic