File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes HibernateException: Hibernate Dialect must be explicitly set Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "HibernateException: Hibernate Dialect must be explicitly set" Watch "HibernateException: Hibernate Dialect must be explicitly set" New topic
Author

HibernateException: Hibernate Dialect must be explicitly set

san krish
Ranch Hand

Joined: Aug 11, 2010
Posts: 41
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

Joined: Aug 11, 2010
Posts: 41
anyone who knows a solution to this or have faced this...please reply. a little urgent.
san krish
Ranch Hand

Joined: Aug 11, 2010
Posts: 41
can someone pleas help me..
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

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

Joined: Aug 11, 2010
Posts: 41
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

Joined: Aug 11, 2010
Posts: 41
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

Joined: Aug 11, 2010
Posts: 41
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

Joined: Apr 15, 2012
Posts: 56

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:
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: HibernateException: Hibernate Dialect must be explicitly set