Hallo,
Ich hoffe jemand kann mir weiterhelfen. Ich hoffe das es ein einfach zu loesendes Problem ist .....
Bei Ausfuehrung des aufgefuehrten Codes tritt eine NullPointer Exception auf...
Rahmenbedingungen:
Versionen
HibernateCore = 3.2
HAnno = 3.2.0
HEManager = 3.2.0
DB: HSQL
Keine XML Konfigurationsdateien !
Code:
Code:
public static void main(String[] args)
{
Ejb3Configuration configuration = new Ejb3Configuration();
configuration.setProperty("hibernate.dialect","org.hibernate.dialect.HSQLDialect");
configuration.setProperty("hibernate.connection.driver_class","org.hsqldb.jdbcDriver");
configuration.setProperty("hibernate.connection.url","jdbc:hsqldb:C:/temp/testData");
configuration.setProperty("hibernate.connection.username","sa");
configuration.setProperty("hibernate.connection.password","");
configuration.addAnnotatedClass(AddressImpl.class);
SchemaExport schemaExport = new SchemaExport(configuration.getHibernateConfiguration());
schemaExport.setOutputFile("c://temp//sql.txt");
schemaExport.create(true,true);
EntityManagerFactory entityManagerFactory = configuration.buildEntityManagerFactory();
EntityManager entityManager = entityManagerFactory.createEntityManager();
EntityTransaction transaction = entityManager.getTransaction();
transaction.begin();
AddressImpl address = new AddressImpl();
entityManager.persist(address); // HIER KOMMT DIE NULLPOINTER
transaction.commit();
entityManager.close();
entityManagerFactory.close();
schemaExport.drop(true,true);
}
Problem:
Code:
2006.11.05 18:37:54,601 INFO [main] - org.hibernate.ejb.Version - Hibernate EntityManager 3.2.0.GA
2006.11.05 18:37:54,691 INFO [main] - org.hibernate.cfg.annotations.Version - Hibernate Annotations 3.2.0.GA
2006.11.05 18:37:54,781 INFO [main] - org.hibernate.cfg.Environment - Hibernate 3.2.0
2006.11.05 18:37:54,801 INFO [main] - org.hibernate.cfg.Environment - hibernate.properties not found
2006.11.05 18:37:54,801 INFO [main] - org.hibernate.cfg.Environment - Bytecode provider name : cglib
2006.11.05 18:37:54,851 INFO [main] - org.hibernate.cfg.Environment - using JDK 1.4 java.sql.Timestamp handling
2006.11.05 18:37:55,622 INFO [main] - org.hibernate.dialect.Dialect - Using dialect: org.hibernate.dialect.HSQLDialect
2006.11.05 18:37:56,163 INFO [main] - org.hibernate.cfg.AnnotationBinder - Binding entity from annotated class: businesslayer.modules.Contact.businessObject.Address._impl.AddressImpl
2006.11.05 18:37:56,323 INFO [main] - org.hibernate.cfg.annotations.EntityBinder - Bind entity businesslayer.modules.Contact.businessObject.Address._impl.AddressImpl on table Address
2006.11.05 18:37:56,834 INFO [main] - org.hibernate.tool.hbm2ddl.SchemaExport - Running hbm2ddl schema export
2006.11.05 18:37:56,844 INFO [main] - org.hibernate.tool.hbm2ddl.SchemaExport - writing generated schema to file: c://temp//sql.txt
2006.11.05 18:37:56,844 INFO [main] - org.hibernate.tool.hbm2ddl.SchemaExport - exporting generated schema to database
2006.11.05 18:37:56,864 INFO [main] - org.hibernate.connection.DriverManagerConnectionProvider - Using Hibernate built-in connection pool (not for production use!)
2006.11.05 18:37:56,864 INFO [main] - org.hibernate.connection.DriverManagerConnectionProvider - Hibernate connection pool size: 20
2006.11.05 18:37:56,864 INFO [main] - org.hibernate.connection.DriverManagerConnectionProvider - autocommit mode: false
2006.11.05 18:37:56,864 INFO [main] - org.hibernate.connection.DriverManagerConnectionProvider - using driver: org.hsqldb.jdbcDriver at URL: jdbc:hsqldb:C:/temp/testData
2006.11.05 18:37:56,864 INFO [main] - org.hibernate.connection.DriverManagerConnectionProvider - connection properties: {user=sa, password=****}
drop table Address if exists
drop table dual_AddressIDSeq if exists
drop sequence AddressIDSeq
create table Address (_addressPK bigint not null, primary key (_addressPK))
create table dual_AddressIDSeq (zero integer)
insert into dual_AddressIDSeq values (0)
create sequence AddressIDSeq start with 1
2006.11.05 18:37:58,086 INFO [main] - org.hibernate.tool.hbm2ddl.SchemaExport - schema export complete
2006.11.05 18:37:58,086 INFO [main] - org.hibernate.connection.DriverManagerConnectionProvider - cleaning up connection pool: jdbc:hsqldb:C:/temp/testData
2006.11.05 18:37:58,126 INFO [main] - org.hibernate.connection.DriverManagerConnectionProvider - Using Hibernate built-in connection pool (not for production use!)
2006.11.05 18:37:58,126 INFO [main] - org.hibernate.connection.DriverManagerConnectionProvider - Hibernate connection pool size: 20
2006.11.05 18:37:58,126 INFO [main] - org.hibernate.connection.DriverManagerConnectionProvider - autocommit mode: false
2006.11.05 18:37:58,126 INFO [main] - org.hibernate.connection.DriverManagerConnectionProvider - using driver: org.hsqldb.jdbcDriver at URL: jdbc:hsqldb:C:/temp/testData
2006.11.05 18:37:58,126 INFO [main] - org.hibernate.connection.DriverManagerConnectionProvider - connection properties: {user=sa, password=****}
2006.11.05 18:37:58,176 INFO [main] - org.hibernate.cfg.SettingsFactory - RDBMS: HSQL Database Engine, version: 1.8.0
2006.11.05 18:37:58,176 INFO [main] - org.hibernate.cfg.SettingsFactory - JDBC driver: HSQL Database Engine Driver, version: 1.8.0
2006.11.05 18:37:58,196 INFO [main] - org.hibernate.dialect.Dialect - Using dialect: org.hibernate.dialect.HSQLDialect
2006.11.05 18:37:58,196 INFO [main] - org.hibernate.transaction.TransactionFactoryFactory - Using default transaction strategy (direct JDBC transactions)
2006.11.05 18:37:58,246 INFO [main] - org.hibernate.transaction.TransactionManagerLookupFactory - No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
2006.11.05 18:37:58,246 INFO [main] - org.hibernate.cfg.SettingsFactory - Automatic flush during beforeCompletion(): disabled
2006.11.05 18:37:58,246 INFO [main] - org.hibernate.cfg.SettingsFactory - Automatic session close at end of transaction: disabled
2006.11.05 18:37:58,246 INFO [main] - org.hibernate.cfg.SettingsFactory - JDBC batch size: 15
2006.11.05 18:37:58,256 INFO [main] - org.hibernate.cfg.SettingsFactory - JDBC batch updates for versioned data: disabled
2006.11.05 18:37:58,256 INFO [main] - org.hibernate.cfg.SettingsFactory - Scrollable result sets: enabled
2006.11.05 18:37:58,256 INFO [main] - org.hibernate.cfg.SettingsFactory - JDBC3 getGeneratedKeys(): disabled
2006.11.05 18:37:58,256 INFO [main] - org.hibernate.cfg.SettingsFactory - Connection release mode: auto
2006.11.05 18:37:58,256 INFO [main] - org.hibernate.cfg.SettingsFactory - Default batch fetch size: 1
2006.11.05 18:37:58,256 INFO [main] - org.hibernate.cfg.SettingsFactory - Generate SQL with comments: disabled
2006.11.05 18:37:58,256 INFO [main] - org.hibernate.cfg.SettingsFactory - Order SQL updates by primary key: disabled
2006.11.05 18:37:58,256 INFO [main] - org.hibernate.cfg.SettingsFactory - Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
2006.11.05 18:37:58,276 INFO [main] - org.hibernate.hql.ast.ASTQueryTranslatorFactory - Using ASTQueryTranslatorFactory
2006.11.05 18:37:58,276 INFO [main] - org.hibernate.cfg.SettingsFactory - Query language substitutions: {}
2006.11.05 18:37:58,276 INFO [main] - org.hibernate.cfg.SettingsFactory - JPA-QL strict compliance: disabled
2006.11.05 18:37:58,276 INFO [main] - org.hibernate.cfg.SettingsFactory - Second-level cache: enabled
2006.11.05 18:37:58,276 INFO [main] - org.hibernate.cfg.SettingsFactory - Query cache: disabled
2006.11.05 18:37:58,276 INFO [main] - org.hibernate.cfg.SettingsFactory - Cache provider: org.hibernate.cache.NoCacheProvider
2006.11.05 18:37:58,276 INFO [main] - org.hibernate.cfg.SettingsFactory - Optimize cache for minimal puts: disabled
2006.11.05 18:37:58,276 INFO [main] - org.hibernate.cfg.SettingsFactory - Structured second-level cache entries: disabled
2006.11.05 18:37:58,296 INFO [main] - org.hibernate.cfg.SettingsFactory - Statistics: disabled
2006.11.05 18:37:58,296 INFO [main] - org.hibernate.cfg.SettingsFactory - Deleted entity synthetic identifier rollback: disabled
2006.11.05 18:37:58,306 INFO [main] - org.hibernate.cfg.SettingsFactory - Default entity-mode: pojo
2006.11.05 18:37:58,516 INFO [main] - org.hibernate.impl.SessionFactoryImpl - building session factory
2006.11.05 18:37:59,678 INFO [main] - org.hibernate.impl.SessionFactoryObjectFactory - Not binding factory to JNDI, no JNDI name configured
Exception in thread "main" java.lang.NullPointerException
at org.hibernate.ejb.event.EJB3PersistEventListener.invokeSaveLifecycle(EJB3PersistEventListener.java:31)
at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:176)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:121)
at org.hibernate.event.def.DefaultPersistEventListener.entityIsTransient(DefaultPersistEventListener.java:131)
at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:87)
at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:38)
at org.hibernate.impl.SessionImpl.firePersist(SessionImpl.java:618)
at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:592)
at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:596)
at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:212)
at test.Test.main(Test.java:38)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:90)
Process finished with exit code 1
Zur Vervollstaendigung:
Code:
package businesslayer.modules.Contact.businessObject.Address._impl;
import javax.persistence.*;
@Entity
@Table(name = AddressTable.TABLENAME)
public class AddressImpl
{
@Id
@GeneratedValue(generator = "Address_Gen",strategy = GenerationType.SEQUENCE)
@SequenceGenerator(name = "Address_Gen",sequenceName = "AddressIDSeq")
public long _addressPK;
public long getAddressPK()
{
return _addressPK;
}
public void setAddressPK(long addressPK)
{
_addressPK = addressPK;
}
}
Meine letzte Alternative waere mir den Source Code von Hibernate reinzuziehen.
Danke im Vorraus fuer eure Bemuehungen
ps: Falls ihr euch auch daran die Zaehne ausbeisst, waere es gut, wenn ihr mir das mitteilen wuerdet. Dann weiss ich wenigstens das ich nicht ganz doof bin ...