Hi I'm new in hibernate.
I'm trying to generate my first, and very simple, example with hibernate. I've solve some problem, but now I can't understand why the system can't generate the id and I've the error
net.sf.hibernate.MappingException: could not instantiate id generator
at net.sf.hibernate.id.IdentifierGeneratorFactory.create(IdentifierGeneratorFactory.java:82)
I've hibernate 2.1 and i'm using mysql.
Code between sessionFactory.openSession() and session.close():
Code:
....
try {
cfg = new Configuration()
.addClass(Utente.class)
.addClass(Gruppo.class)
.addClass(Autorizzazioni.class)
.setProperty(Environment.HBM2DDL_AUTO, "create");
SessionFactory sf = cfg.buildSessionFactory();
System.out.println("tre");
} catch (MappingException e) {
e.printStackTrace();
}
File .hbm.xml:Quote:
<?xml version="1.0" ?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping package="com.omeopatici.dati.db.struttureDati" >
<class name="Utente" table="utente">
<id name="codice_utente" column="id_utente" type="int">
<generator class="sequence" >
<param name="sequence">id_sequence</param>
</generator>
</id>
<property name="nome" column="nome" not-null="true" type="java.lang.String" />
<property name="cognome" column="cognome" not-null="true" type="java.lang.String" />
<property name="user" column="username" not-null="true" type="java.lang.String" />
<property name="pwd" column="password" not-null="true" type="java.lang.String" />
<property name="cod_oti" column="cod_oti" type="java.lang.String" />
<property name="abilitato" column="abilitato" not-null="true" type="boolean" />
<set name="gruppi" lazy="true" table="nel">
<key column="id_utente"/>
<many-to-many class="Gruppo" column="id_gruppo" />
</set>
</class>
</hibernate-mapping>
Quote:
<?xml version="1.0" ?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping package="com.omeopatici.dati.db.struttureDati" >
<class name="Gruppo" table="gruppo">
<id name="cod_gruppo" column="id_gruppo" type="int">
<generator class="sequence" >
<param name="sequence">id_sequence</param>
</generator>
</id>
<property name="gruppo" column="nome_gruppo" not-null="true" type="java.lang.String" />
<property name="abilitato" column="abilitato" not-null="true" type="char" />
<set name="funzioni" lazy="true" table="autorizza_gruppo">
<key column="id_gruppo"/>
<many-to-many class="Autorizzazioni" column="id_autorizzazioni" />
</set>
</class>
</hibernate-mapping>
Quote:
<?xml version="1.0" ?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping package="com.omeopatici.dati.db.struttureDati" >
<class name="Autorizzazioni" table="Autorizzazioni">
<id name="codice" column="cod_auto" type="int">
<generator class="sequence" >
<param name="sequence">id_sequence</param>
</generator>
</id>
<property name="funzionalita" column="funzionalita" not-null="true" type="java.lang.String" />
</class>
</hibernate-mapping>
File hibernate.properties:## MySQL
hibernate.dialect net.sf.hibernate.dialect.MySQLDialect
hibernate.connection.driver_class org.gjt.mm.mysql.Driver
hibernate.connection.driver_class com.mysql.jdbc.Driver
hibernate.connection.url jdbc:mysql://localhost/progetto
hibernate.connection.username root
hibernate.connection.password
File hibernate.cfg.xmlQuote:
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">
<hibernate-configuration>
<session-factory name="sf">
<property name="dialect">
net.sf.hibernate.dialect.MySQLDialect
</property>
<property name="show_sql">true</property>
<property name="ude_outer_join">true</property>
<property name="hibernate.connection.driver_class"> com.mysql.jdbc.Driver
</property>
<mapping resource = "com/omeopatici/dati/db/struttureDati/Utente.hbm.xml"/>
<mapping resource ="com/omeopatici/dati/db/struttureDati/Gruppo.hbm.xml"/>
<mapping resource ="com/omeopatici/dati/db/struttureDati/Autorizzazioni.hbm.xml"/>
<class-cache
class="com.omeopatici.dati.db.struttureDati.Utente"
region="Utente"
usage="read-write"/>
<class-cache
class="com.omeopatici.dati.db.struttureDati.Gruppo"
region="Gruppo"
usage="read-write"/>
<class-cache
class="com.omeopatici.dati.db.struttureDati.Autorizzazioni"
region="Autorizzazioni"
usage="read-write"/>
</session-factory>
</hibernate-configuration>
Full stack trace of any exception that occurs:Code:
10:16:30,957 INFO Environment:483 - Hibernate 2.1.8
10:16:31,117 INFO Environment:517 - loaded properties from resource hibernate.properties: {hibernate.connection.password=, hibernate.jdbc.batch_versioned_data=true, hibernate.query.substitutions=true 1, false 0, yes 'Y', no 'N', hibernate.cache.region_prefix=hibernate.test, hibernate.show_sql=true, hibernate.proxool.pool_alias=pool1, hibernate.c3p0.max_statements=0, hibernate.jdbc.batch_size=0, hibernate.cache.use_query_cache=true, hibernate.jdbc.use_streams_for_binary=true, hibernate.max_fetch_depth=1, hibernate.connection.pool_size=1, hibernate.connection.username=root, hibernate.connection.driver_class=com.mysql.jdbc.Driver, hibernate.cache.provider_class=net.sf.hibernate.cache.EhCacheProvider, hibernate.cglib.use_reflection_optimizer=true, hibernate.dialect=net.sf.hibernate.dialect.MySQLDialect, hibernate.connection.url=jdbc:mysql://localhost/progetto}
10:16:31,398 INFO Environment:542 - using java.io streams to persist binary types
10:16:31,398 INFO Environment:543 - using CGLIB reflection optimizer
10:16:31,898 INFO Environment:572 - using JDK 1.4 java.sql.Timestamp handling
10:16:32,099 INFO Configuration:351 - Mapping resource: com/omeopatici/dati/db/struttureDati/Utente.hbm.xml
10:16:36,044 INFO Binder:229 - Mapping class: com.omeopatici.dati.db.struttureDati.Utente -> utente
10:16:36,675 INFO Binder:571 - Mapping collection: com.omeopatici.dati.db.struttureDati.Utente.gruppi -> nel
10:16:36,735 INFO Configuration:351 - Mapping resource: com/omeopatici/dati/db/struttureDati/Gruppo.hbm.xml
10:16:36,915 INFO Binder:229 - Mapping class: com.omeopatici.dati.db.struttureDati.Gruppo -> gruppo
10:16:36,956 INFO Binder:571 - Mapping collection: com.omeopatici.dati.db.struttureDati.Gruppo.funzioni -> autorizza_gruppo
10:16:36,976 INFO Configuration:351 - Mapping resource: com/omeopatici/dati/db/struttureDati/Autorizzazioni.hbm.xml
10:16:37,176 INFO Binder:229 - Mapping class: com.omeopatici.dati.db.struttureDati.Autorizzazioni -> Autorizzazioni
10:16:37,186 INFO Configuration:641 - processing one-to-many association mappings
10:16:37,226 INFO Configuration:650 - processing one-to-one association property references
10:16:37,226 INFO Configuration:675 - processing foreign key constraints
10:16:37,737 INFO Dialect:86 - Using dialect: net.sf.hibernate.dialect.MySQLDialect
10:16:37,787 INFO SettingsFactory:70 - Maximim outer join fetch depth: 1
10:16:37,797 INFO SettingsFactory:74 - Use outer join fetching: true
10:16:37,827 INFO DriverManagerConnectionProvider:42 - Using Hibernate built-in connection pool (not for production use!)
10:16:37,827 INFO DriverManagerConnectionProvider:43 - Hibernate connection pool size: 1
10:16:38,047 INFO DriverManagerConnectionProvider:77 - using driver: com.mysql.jdbc.Driver at URL: jdbc:mysql://localhost/progetto
10:16:38,047 INFO DriverManagerConnectionProvider:78 - connection properties: {user=root, password=}
10:16:38,127 INFO TransactionManagerLookupFactory:33 - No TransactionManagerLookup configured (in JTA environment, use of process level read-write cache is not recommended)
10:16:46,279 INFO SettingsFactory:114 - Use scrollable result sets: true
10:16:46,289 INFO SettingsFactory:117 - Use JDBC3 getGeneratedKeys(): true
10:16:46,289 INFO SettingsFactory:120 - Optimize cache for minimal puts: false
10:16:46,289 INFO SettingsFactory:126 - echoing all SQL to stdout
10:16:46,299 INFO SettingsFactory:129 - Query language substitutions: {no='N', true=1, yes='Y', false=0}
10:16:46,790 INFO SettingsFactory:140 - cache provider: net.sf.hibernate.cache.EhCacheProvider
10:16:47,090 INFO SettingsFactory:152 - query cache factory: net.sf.hibernate.cache.StandardQueryCacheFactory
10:16:47,210 INFO Configuration:1130 - instantiating and configuring caches
10:16:50,805 INFO SessionFactoryImpl:119 - building session factory
net.sf.hibernate.MappingException: could not instantiate id generator
at net.sf.hibernate.id.IdentifierGeneratorFactory.create(IdentifierGeneratorFactory.java:82)
at net.sf.hibernate.mapping.SimpleValue.createIdentifierGenerator(SimpleValue.java:82)
at net.sf.hibernate.persister.AbstractEntityPersister.<init>(AbstractEntityPersister.java:644)
at net.sf.hibernate.persister.EntityPersister.<init>(EntityPersister.java:690)
at net.sf.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:42)
at net.sf.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:137)
at net.sf.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:805)
at com.omeopatici.dati.db.operazioni.GestioneUtente.<init>(GestioneUtente.java:48)
at com.omeopatici.dati.db.solotestatute.Accesso.Ins_actionPerformed(Accesso.java:100)
at com.omeopatici.dati.db.solotestatute.Accesso$1.actionPerformed(Accesso.java:82)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1764)
at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.java:1817)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:419)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:257)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:245)
at java.awt.Component.processMouseEvent(Component.java:5134)
at java.awt.Component.processEvent(Component.java:4931)
at java.awt.Container.processEvent(Container.java:1566)
at java.awt.Component.dispatchEventImpl(Component.java:3639)
at java.awt.Container.dispatchEventImpl(Container.java:1623)
at java.awt.Component.dispatchEvent(Component.java:3480)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3450)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3165)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3095)
at java.awt.Container.dispatchEventImpl(Container.java:1609)
at java.awt.Window.dispatchEventImpl(Window.java:1590)
at java.awt.Component.dispatchEvent(Component.java:3480)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:450)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:197)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:144)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:136)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:99)
Caused by: net.sf.hibernate.MappingException: Dialect does not support sequences
at net.sf.hibernate.dialect.Dialect.getSequenceNextValString(Dialect.java:335)
at net.sf.hibernate.id.SequenceGenerator.configure(SequenceGenerator.java:57)
at net.sf.hibernate.id.IdentifierGeneratorFactory.create(IdentifierGeneratorFactory.java:78)
... 32 more
java.lang.NullPointerException
at com.omeopatici.dati.db.operazioni.GestioneUtente.InserisciUtente(GestioneUtente.java:84)
at com.omeopatici.dati.db.solotestatute.Accesso.Ins_actionPerformed(Accesso.java:101)
at com.omeopatici.dati.db.solotestatute.Accesso$1.actionPerformed(Accesso.java:82)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1764)
at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.java:1817)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:419)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:257)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:245)
at java.awt.Component.processMouseEvent(Component.java:5134)
at java.awt.Component.processEvent(Component.java:4931)
at java.awt.Container.processEvent(Container.java:1566)
at java.awt.Component.dispatchEventImpl(Component.java:3639)
at java.awt.Container.dispatchEventImpl(Container.java:1623)
at java.awt.Component.dispatchEvent(Component.java:3480)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3450)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3165)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3095)
at java.awt.Container.dispatchEventImpl(Container.java:1609)
at java.awt.Window.dispatchEventImpl(Window.java:1590)
at java.awt.Component.dispatchEvent(Component.java:3480)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:450)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:197)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:144)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:136)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:99)
null
null
Can someone help me please!!!!