我已经在数据库中建好了一个TBUSER表,这表里就一个主键字段。。没别的了,就是为了测试
然后用annotation写了一个User类
- Java code
@Entity@Table(name = "TBUSER")@GenericGenerator(name = "user_increment", strategy = "increment")public class User { private int id; @Id @Column(name = "UID") @GeneratedValue(generator = "user_increment") public int getId() { return id; } public void setId(int id) { this.id = id; }}
然后写了个测试的main方法,想往表里放一条记录:
- Java code
public static void main(String[] args) { // TODO Auto-generated method stub Session session = HibernateSessionFactory.getSession(); session.beginTransaction(); User u = new User(); session.save(u); session.getTransaction().commit(); session.close(); }
但是提示错误:
- Java code
log4j:WARN No appenders could be found for logger (org.hibernate.cfg.annotations.Version).log4j:WARN Please initialize the log4j system properly.Hibernate: select max(UID) from TBUSERHibernate: insert into TBUSER (UID) values (?)Exception in thread "main" org.hibernate.exception.SQLGrammarException: Could not execute JDBC batch update at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:90) at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66) at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:275) at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:266) at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:167) at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321) at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50) at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1028) at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:366) at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:137) at com.hib.entity.Test.main(Test.java:18)Caused by: java.sql.BatchUpdateException: ORA-00928: 缺失 SELECT 关键字 at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:10070) at oracle.jdbc.driver.OracleStatementWrapper.executeBatch(OracleStatementWrapper.java:213) at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:70) at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:268) ... 8 more
求解啊。。。大侠们
------解决方案--------------------
oracle自动增长主键应该是sequence吧,主键的生成策略你再看看