I got the same problem:
Annotation:
Code:
@Id
@Column(name = "id", unique = true, nullable = false)
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SEQ_GEN")
@SequenceGenerator(name = "SEQ_GEN", sequenceName = "OnlyTest_id_seq", allocationSize = 10)
Table:
Code:
CREATE TABLE "OnlyTest"
(
id serial NOT NULL,
"name" character varying(80) NOT NULL,
CONSTRAINT "OnlyTest_pkey" PRIMARY KEY (id)
)
Sequence:
Code:
CREATE SEQUENCE "OnlyTest_id_seq"
INCREMENT 1
MINVALUE 1
MAXVALUE 9223372036854775807
START 1
CACHE 1;
Test Code:
Code:
EntityManagerFactory emf = Persistence.createEntityManagerFactory("er1PU");
EntityManager em = emf.createEntityManager(); // Retrieve an application managed entity manager
OnlyTest e = new OnlyTest();
e.setName("aa");
em.persist(e);
em.close();
emf.close();
And Log:
Code:
15:43:14,609 INFO Version:15 - Hibernate Annotations 3.3.1.GA
15:43:14,640 INFO Environment:514 - Hibernate 3.2.6
15:43:14,640 INFO Environment:547 - hibernate.properties not found
15:43:14,656 INFO Environment:681 - Bytecode provider name : cglib
15:43:14,656 INFO Environment:598 - using JDK 1.4 java.sql.Timestamp handling
15:43:14,734 INFO Version:15 - Hibernate EntityManager 3.3.2.GA
15:43:14,765 DEBUG Ejb3Configuration:209 - Look up for persistence unit: er1PU
15:43:14,781 DEBUG Ejb3Configuration:221 - Analysing persistence.xml: file:/E:/entityPrjojectNetbeans/projects/er1/build/classes/META-INF/persistence.xml
15:43:15,296 DEBUG PersistenceXmlLoader:156 - Persistent Unit name from persistence.xml: er1PU
15:43:15,296 DEBUG Ejb3Configuration:228 - PersistenceMetadata [
name: er1PU
jtaDataSource: null
nonJtaDataSource: null
transactionType: RESOURCE_LOCAL
provider: org.hibernate.ejb.HibernatePersistence
classes[
er1.Attributes er1.Entities er1.OnlyTest ]
packages[
]
mappingFiles[
]
jarFiles[
]
hbmfiles: 0
properties[
hibernate.connection.username: postgres
hibernate.connection.password: 12345
hibernate.cache.provider_class: org.hibernate.cache.NoCacheProvider
hibernate.connection.url: jdbc:postgresql://localhost:5432/domains
hibernate.connection.driver_class: org.postgresql.Driver
]]
15:43:15,312 DEBUG JarVisitorFactory:73 - JAR URL from URL Entry: file:/E:/entityPrjojectNetbeans/projects/er1/build/classes/META-INF/persistence.xml >> file:/E:/entityPrjojectNetbeans/projects/er1/build/classes/
15:43:15,312 DEBUG Ejb3Configuration:562 - Detect class: true; detect hbm: true
15:43:15,343 DEBUG AbstractJarVisitor:116 - Searching mapped entities in jar/par: file:/E:/entityPrjojectNetbeans/projects/er1/build/classes/
15:43:15,343 DEBUG AbstractJarVisitor:162 - Filtering: er1.Attributes
15:43:15,421 DEBUG AbstractJarVisitor:213 - Java element filter matched for er1.Attributes
15:43:15,421 DEBUG AbstractJarVisitor:162 - Filtering: er1.Entities
15:43:15,437 DEBUG AbstractJarVisitor:213 - Java element filter matched for er1.Entities
15:43:15,437 DEBUG AbstractJarVisitor:162 - Filtering: er1.Main
15:43:15,437 DEBUG AbstractJarVisitor:162 - Filtering: er1.OnlyTest
15:43:15,437 DEBUG AbstractJarVisitor:213 - Java element filter matched for er1.OnlyTest
15:43:15,437 DEBUG Ejb3Configuration:562 - Detect class: true; detect hbm: true
15:43:15,437 DEBUG Ejb3Configuration:158 - Creating Factory: er1PU
15:43:15,562 INFO AnnotationBinder:418 - Binding entity from annotated class: er1.Attributes
15:43:15,578 INFO QueryBinder:64 - Binding Named query: Attributes.findAll => SELECT a FROM Attributes a
15:43:15,578 INFO QueryBinder:64 - Binding Named query: Attributes.findById => SELECT a FROM Attributes a WHERE a.id = :id
15:43:15,578 INFO QueryBinder:64 - Binding Named query: Attributes.findByFarname => SELECT a FROM Attributes a WHERE a.farname = :farname
15:43:15,640 INFO EntityBinder:424 - Bind entity er1.Attributes on table attributes
15:43:15,718 INFO AnnotationBinder:418 - Binding entity from annotated class: er1.Entities
15:43:15,718 INFO QueryBinder:64 - Binding Named query: Entities.findAll => SELECT e FROM Entities e
15:43:15,718 INFO QueryBinder:64 - Binding Named query: Entities.findById => SELECT e FROM Entities e WHERE e.id = :id
15:43:15,718 INFO QueryBinder:64 - Binding Named query: Entities.findByFarname => SELECT e FROM Entities e WHERE e.farname = :farname
15:43:15,718 INFO QueryBinder:64 - Binding Named query: Entities.findByEngname => SELECT e FROM Entities e WHERE e.engname = :engname
15:43:15,718 INFO QueryBinder:64 - Binding Named query: Entities.findByComment => SELECT e FROM Entities e WHERE e.comment = :comment
15:43:15,718 INFO EntityBinder:424 - Bind entity er1.Entities on table entities
15:43:15,781 INFO AnnotationBinder:418 - Binding entity from annotated class: er1.OnlyTest
15:43:15,781 INFO QueryBinder:64 - Binding Named query: OnlyTest.findAll => SELECT o FROM OnlyTest o
15:43:15,781 INFO QueryBinder:64 - Binding Named query: OnlyTest.findById => SELECT o FROM OnlyTest o WHERE o.id = :id
15:43:15,781 INFO QueryBinder:64 - Binding Named query: OnlyTest.findByName => SELECT o FROM OnlyTest o WHERE o.name = :name
15:43:15,781 INFO EntityBinder:424 - Bind entity er1.OnlyTest on table OnlyTest
15:43:15,859 INFO CollectionBinder:651 - Mapping collection: er1.Entities.attributesCollection -> attributes
15:43:15,875 INFO AnnotationConfiguration:365 - Hibernate Validator not found: ignoring
15:43:15,906 DEBUG NamingHelper:30 - No JNDI name configured for binding Ejb3Configuration
15:43:15,922 INFO DriverManagerConnectionProvider:41 - Using Hibernate built-in connection pool (not for production use!)
15:43:15,922 INFO DriverManagerConnectionProvider:42 - Hibernate connection pool size: 20
15:43:15,922 INFO DriverManagerConnectionProvider:45 - autocommit mode: true
15:43:15,937 INFO DriverManagerConnectionProvider:80 - using driver: org.postgresql.Driver at URL: jdbc:postgresql://localhost:5432/domains
15:43:15,937 INFO DriverManagerConnectionProvider:86 - connection properties: {user=postgres, password=****, autocommit=true, release_mode=auto}
15:43:16,125 INFO SettingsFactory:89 - RDBMS: PostgreSQL, version: 8.3.3
15:43:16,125 INFO SettingsFactory:90 - JDBC driver: PostgreSQL Native Driver, version: PostgreSQL 8.3 JDBC3 with SSL (build 603)
15:43:16,156 INFO Dialect:152 - Using dialect: org.hibernate.dialect.PostgreSQLDialect
15:43:16,156 INFO TransactionFactoryFactory:34 - Transaction strategy: org.hibernate.transaction.JDBCTransactionFactory
15:43:16,172 INFO TransactionManagerLookupFactory:33 - No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
15:43:16,172 INFO SettingsFactory:143 - Automatic flush during beforeCompletion(): disabled
15:43:16,172 INFO SettingsFactory:147 - Automatic session close at end of transaction: disabled
15:43:16,172 INFO SettingsFactory:154 - JDBC batch size: 15
15:43:16,172 INFO SettingsFactory:157 - JDBC batch updates for versioned data: disabled
15:43:16,172 INFO SettingsFactory:162 - Scrollable result sets: enabled
15:43:16,172 INFO SettingsFactory:170 - JDBC3 getGeneratedKeys(): disabled
15:43:16,187 INFO SettingsFactory:178 - Connection release mode: auto
15:43:16,187 INFO SettingsFactory:205 - Default batch fetch size: 1
15:43:16,187 INFO SettingsFactory:209 - Generate SQL with comments: disabled
15:43:16,187 INFO SettingsFactory:213 - Order SQL updates by primary key: disabled
15:43:16,187 INFO SettingsFactory:217 - Order SQL inserts for batching: disabled
15:43:16,203 INFO SettingsFactory:386 - Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
15:43:16,203 INFO ASTQueryTranslatorFactory:24 - Using ASTQueryTranslatorFactory
15:43:16,203 INFO SettingsFactory:225 - Query language substitutions: {}
15:43:16,203 INFO SettingsFactory:230 - JPA-QL strict compliance: enabled
15:43:16,203 INFO SettingsFactory:235 - Second-level cache: enabled
15:43:16,203 INFO SettingsFactory:239 - Query cache: disabled
15:43:16,219 INFO SettingsFactory:373 - Cache provider: org.hibernate.cache.NoCacheProvider
15:43:16,219 INFO SettingsFactory:254 - Optimize cache for minimal puts: disabled
15:43:16,219 INFO SettingsFactory:263 - Structured second-level cache entries: disabled
15:43:16,234 INFO SettingsFactory:290 - Statistics: disabled
15:43:16,234 INFO SettingsFactory:294 - Deleted entity synthetic identifier rollback: disabled
15:43:16,234 INFO SettingsFactory:309 - Default entity-mode: pojo
15:43:16,234 INFO SettingsFactory:313 - Named query checking : enabled
15:43:16,266 INFO SessionFactoryImpl:161 - building session factory
15:43:16,641 INFO SessionFactoryObjectFactory:82 - Not binding factory to JNDI, no JNDI name configured
15:43:16,953 DEBUG SQL:401 - select nextval ('OnlyTest_id_seq')
15:43:16,985 WARN JDBCExceptionReporter:77 - SQL Error: 0, SQLState: 42P01
15:43:16,985 ERROR JDBCExceptionReporter:78 - ERROR: relation "onlytest_id_seq" does not exist
15:43:16,985 DEBUG AbstractEntityManagerImpl:425 - mark transaction for rollback
Exception in thread "main" javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not get next sequence value
at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:637)
at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:226)
at er1.Main.main(Main.java:29)
Caused by: org.hibernate.exception.SQLGrammarException: could not get next sequence value
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.id.SequenceGenerator.generate(SequenceGenerator.java:96)
at org.hibernate.id.SequenceHiLoGenerator.generate(SequenceHiLoGenerator.java:58)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:99)
at org.hibernate.ejb.event.EJB3PersistEventListener.saveWithGeneratedId(EJB3PersistEventListener.java:49)
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:220)
... 1 more
Caused by: org.postgresql.util.PSQLException: ERROR: relation "onlytest_id_seq" does not exist
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:1592)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1327)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:192)
at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:451)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:350)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:254)
at org.hibernate.id.SequenceGenerator.generate(SequenceGenerator.java:75)
... 11 more
Java Result: 1
Any suggestion?