Logo 
Search:

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: 6287
  

what is the cause of error below at the first page AddItem.jsp of
the example for Hibernate in
homepage.mac.com/.../example1.html


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

at org.apache.catalina.connector.http.HttpProcessor.run
(HttpProcessor.java:1125)
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
(Dialect.java:305)
at net.sf.hibernate.persister.AbstractEntityPersister.
(AbstractEntityPersister.java:646)
at net.sf.hibernate.persister.EntityPersister.
(EntityPersister.java:690)
at
net.sf.hibernate.persister.PersisterFactory.createClassPersister
(PersisterFactory.java:42)
at net.sf.hibernate.impl.SessionFactoryImpl.
(SessionFactoryImpl.java:137)
at net.sf.hibernate.cfg.Configuration.buildSessionFactory
(Configuration.java:805)
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">
<head>
<title>Example 1</title>
<html:base/>
</head>
<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
<code>test</code>.</p>
<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" >
<tr>
<td><bean:write name="element" property="name" /></td>
<td><bean:write name="element" property="description" /></td>

</tr>
</logic:iterate>
</table>
<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>
<td>description:</td><td><html:text
property="description" /></td></tr>
</table><br/>
<html:submit />
</html:form>
</body>
</html:html>


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
try
{

Configuration cfg = new Configuration
().addClass(Item.class);

sessionFactory = cfg.buildSessionFactory();

}
catch (MappingException e)
{

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

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

}


public static synchronized ConnectionFactory getInstance()
{

if (instance == null)
{
instance = new ConnectionFactory
();/////////////////////////////error//////Line:103
}
return instance;
}


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

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

}

Share: 

 

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 .

 




Tagged: