Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Hibernate : Dialect does not support identity key generation

  Asked By: Steven    Date: May 17    Category: Java    Views: 8851

what is the cause of error below at the first page AddItem.jsp of
the example for Hibernate in

java.lang.RuntimeException: net.sf.hibernate.MappingException:
Dialect does not support identity key generation
at general.ConnectionFactory.(ConnectionFactory.java:69)
at general.ConnectionFactory.getInstance
at general.ItemService.getItemList(ItemService.java:205)
at org.apache.jsp.AddItem$jsp._jspService
at org.apache.jasper.runtime.HttpJspBase.service
at javax.servlet.http.HttpServlet.service

at org.apache.catalina.connector.http.HttpProcessor.run
at java.lang.Thread.run(Thread.java:536)
Caused by: net.sf.hibernate.MappingException: Dialect does not
support identity key generation
at net.sf.hibernate.dialect.Dialect.getIdentitySelectString
at net.sf.hibernate.persister.AbstractEntityPersister.
at net.sf.hibernate.persister.EntityPersister.
at net.sf.hibernate.impl.SessionFactoryImpl.
at net.sf.hibernate.cfg.Configuration.buildSessionFactory
at general.ConnectionFactory.(ConnectionFactory.java:57)
... 39 more

<%@ taglib uri="/tags/struts-bean" prefix="bean" %>
<%@ taglib uri="/tags/struts-html" prefix="html" %>
<%@ taglib uri="/tags/struts-logic" prefix="logic" %>

<%@ page import="general.ItemService" %>
<%@ page import="java.util.List" %>

<html:html locale="true">
<title>Example 1</title>
<body bgcolor="white">

<h3>Example 1</h3>
<html:errors />

List itemList = ItemService.getInstance().getItemList();
request.setAttribute("items", itemList);
<p>List of items in <code>item</code> table of database
<table border=1>
<!-- This code will iterate over the list of items, creating a table
row for each item. -->
<logic:iterate id="element" name="items" scope="request"
type="general.Item" >
<td><bean:write name="element" property="name" /></td>
<td><bean:write name="element" property="description" /></td>

<p>Sumbit to add an item:</p>

<!-- This form will post the submitted data to the addItem Action
Mapping -->
<html:form action="addItem.do" method="post">
<table border=1>
<tr><td>name:</td><td><html:text property="name" /></td>
property="description" /></td></tr>
<html:submit />

package general;

import net.sf.hibernate.HibernateException;
import net.sf.hibernate.MappingException;
import net.sf.hibernate.Session;
import net.sf.hibernate.SessionFactory;
import net.sf.hibernate.cfg.Configuration;

public class ConnectionFactory

private static ConnectionFactory instance = null;
private SessionFactory sessionFactory = null;

private ConnectionFactory()
// Establish SessionFactory for Hibernate

Configuration cfg = new Configuration

sessionFactory = cfg.buildSessionFactory();

catch (MappingException e)

System.err.println("Mapping Exception" +
throw new RuntimeException
(e);/////////////////////////error//////////Line : 69
catch (HibernateException e)

System.err.println("Hibernate Exception" +
throw new RuntimeException(e);


public static synchronized ConnectionFactory getInstance()

if (instance == null)
instance = new ConnectionFactory
return instance;

public Session getSession()
Session s = sessionFactory.openSession();
return s;
catch (HibernateException e)

System.err.println("Hibernate Exception" +
throw new RuntimeException(e);




1 Answer Found

Answer #1    Answered By: Viren Rajput     Answered On: May 17

I guess you have used
<generator class = "identity"/>
in Item.hbm.xml file .you should exchange it with
<generator class="native"/>.
For more info refer to hibernate-refrence .