我正在用hibernate做一个项目,涉及到用户和角色的多对多问题。hibernate中有<Many-To-Mang>或者@ManyToMany这种方式实现多对多,但是我感觉非常不灵活,也许是我不知道怎么弄。。就拿我这用户和角色说,比如我想记录下某个用户被赋予某个角色的时间,或者授予角色的管理员是谁,这些信息应该记录在关系表中吧。。如果用上面两个方式,用户实体类和角色实体类中的引用都是对方的类型,访问不到我刚提到的授予时间和授予者的信息。还有,如果我想解除一个关系,我是想删除中间表的一条记录,而不是删除用户或者角色表中的记录,这些要求<Many-To-Mang>貌似都达不到啊是不是应该手动将多对多关系分解成多个一对多??求指教~
解决方案 »
- java加载图片
- 大家赶紧解决一下 struts.properties里面的问题 -----不知道啥意思啊
- java 查询sql server 只有英文时没错,一旦字段中包括英文和数字是 不能查询
- spring+Hibermate 的问题!
- Tapertry中的contrib:When和contrib:Otherwise如何使用?
- java小问题
- javamail中有关于ssl的东西吗?
- 在一个类里面经过处理将数据赋到一个数组里,如何将此数组作为一个参数传到另一个类的方法里?
- 有关CMP Entity Bean发布到WebLogic8.1上的问题!
- 两个bean管理的无状态sessionbean传递事务的问题,请高手指教?
- SQL语句中,使用where 条件 in (字段)的问题
- 求指导如何学习J2EE架构的一些管理系统的开发
二月 29, 2012 2:03:23 下午 org.hibernate.annotations.common.Version <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {4.0.1.Final}
二月 29, 2012 2:03:23 下午 org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {4.1.0.Final}
二月 29, 2012 2:03:23 下午 org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
二月 29, 2012 2:03:23 下午 org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
二月 29, 2012 2:03:23 下午 org.hibernate.cfg.Configuration configure
INFO: HHH000043: Configuring from resource: /hibernate.cfg.xml
二月 29, 2012 2:03:23 下午 org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: HHH000040: Configuration resource: /hibernate.cfg.xml
二月 29, 2012 2:03:24 下午 org.hibernate.cfg.Configuration doConfigure
INFO: HHH000041: Configured SessionFactory: null
二月 29, 2012 2:03:24 下午 org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000402: Using Hibernate built-in connection pool (not for production use!)
二月 29, 2012 2:03:24 下午 org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000115: Hibernate connection pool size: 20
二月 29, 2012 2:03:24 下午 org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000006: Autocommit mode: false
二月 29, 2012 2:03:24 下午 org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000401: using driver [oracle.jdbc.driver.OracleDriver] at URL [jdbc:oracle:thin:@localhost:1521:orcl]
二月 29, 2012 2:03:24 下午 org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000046: Connection properties: {user=PBUser, password=****}
二月 29, 2012 2:03:25 下午 org.hibernate.dialect.Dialect <init>
INFO: HHH000400: Using dialect: org.hibernate.dialect.Oracle10gDialect
二月 29, 2012 2:03:25 下午 org.hibernate.engine.jdbc.internal.LobCreatorBuilder useContextualLobCreation
INFO: HHH000424: Disabling contextual LOB creation as createClob() method threw error : java.lang.reflect.InvocationTargetException
二月 29, 2012 2:03:25 下午 org.hibernate.engine.transaction.internal.TransactionFactoryInitiator initiateService
INFO: HHH000399: Using default transaction strategy (direct JDBC transactions)
二月 29, 2012 2:03:25 下午 org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory <init>
INFO: HHH000397: Using ASTQueryTranslatorFactory
二月 29, 2012 2:03:26 下午 org.hibernate.tool.hbm2ddl.SchemaExport execute
INFO: HHH000227: Running hbm2ddl schema export
Hibernate:
drop table User cascade constraints
二月 29, 2012 2:03:26 下午 org.hibernate.tool.hbm2ddl.SchemaExport perform
ERROR: HHH000389: Unsuccessful: drop table User cascade constraints
Hibernate:
create table User (
id number(10,0) not null,
primary key (id)
)
二月 29, 2012 2:03:26 下午 org.hibernate.tool.hbm2ddl.SchemaExport perform
ERROR: ORA-00903: 表名无效二月 29, 2012 2:03:26 下午 org.hibernate.tool.hbm2ddl.SchemaExport perform
ERROR: HHH000389: Unsuccessful: create table User (id number(10,0) not null, primary key (id))
二月 29, 2012 2:03:26 下午 org.hibernate.tool.hbm2ddl.SchemaExport perform
ERROR: ORA-00903: 表名无效二月 29, 2012 2:03:26 下午 org.hibernate.tool.hbm2ddl.SchemaExport execute
INFO: HHH000230: Schema export complete
Hibernate:
insert
into
User
(id)
values
(?)
二月 29, 2012 2:03:27 下午 org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
WARN: SQL Error: 903, SQLState: 42000
二月 29, 2012 2:03:27 下午 org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
ERROR: ORA-00903: 表名无效Exception in thread "main" org.hibernate.exception.SQLGrammarException: ORA-00903: 表名无效 at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:122)
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:125)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:110)
at org.hibernate.engine.jdbc.internal.proxy.AbstractStatementProxyHandler.continueInvocation(AbstractStatementProxyHandler.java:129)
at org.hibernate.engine.jdbc.internal.proxy.AbstractProxyHandler.invoke(AbstractProxyHandler.java:81)
at $Proxy7.executeUpdate(Unknown Source)
at org.hibernate.engine.jdbc.batch.internal.NonBatchingBatch.addToBatch(NonBatchingBatch.java:56)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2856)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3297)
at org.hibernate.action.internal.EntityInsertAction.execute(EntityInsertAction.java:88)
at org.hibernate.engine.spi.ActionQueue.execute(ActionQueue.java:362)
at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:354)
at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:275)
at org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:326)
at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:52)
at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1127)
at org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:325)
at org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.beforeTransactionCommit(JdbcTransaction.java:101)
at org.hibernate.engine.transaction.spi.AbstractTransactionImpl.commit(AbstractTransactionImpl.java:175)
at com.aga.entity.Test.main(Test.java:17)
Caused by: java.sql.SQLException: ORA-00903: 表名无效 at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:331)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:288)
at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:743)
at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:213)
at oracle.jdbc.driver.T4CPreparedStatement.executeForRows(T4CPreparedStatement.java:952)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1160)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3285)
at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:3368)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.hibernate.engine.jdbc.internal.proxy.AbstractStatementProxyHandler.continueInvocation(AbstractStatementProxyHandler.java:122)
... 16 more
二月 29, 2012 2:28:34 下午 org.hibernate.annotations.common.Version <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {4.0.1.Final}
二月 29, 2012 2:28:34 下午 org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {4.1.0.Final}
二月 29, 2012 2:28:34 下午 org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
二月 29, 2012 2:28:34 下午 org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
二月 29, 2012 2:28:34 下午 org.hibernate.cfg.Configuration configure
INFO: HHH000043: Configuring from resource: /hibernate.cfg.xml
二月 29, 2012 2:28:34 下午 org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: HHH000040: Configuration resource: /hibernate.cfg.xml
二月 29, 2012 2:28:34 下午 org.hibernate.cfg.Configuration doConfigure
INFO: HHH000041: Configured SessionFactory: null
二月 29, 2012 2:28:35 下午 org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000402: Using Hibernate built-in connection pool (not for production use!)
二月 29, 2012 2:28:35 下午 org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000115: Hibernate connection pool size: 20
二月 29, 2012 2:28:35 下午 org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000006: Autocommit mode: false
二月 29, 2012 2:28:35 下午 org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000401: using driver [oracle.jdbc.driver.OracleDriver] at URL [jdbc:oracle:thin:@localhost:1521:orcl]
二月 29, 2012 2:28:35 下午 org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000046: Connection properties: {user=PBUser, password=****}
二月 29, 2012 2:28:36 下午 org.hibernate.dialect.Dialect <init>
INFO: HHH000400: Using dialect: org.hibernate.dialect.Oracle10gDialect
二月 29, 2012 2:28:36 下午 org.hibernate.engine.jdbc.internal.LobCreatorBuilder useContextualLobCreation
INFO: HHH000424: Disabling contextual LOB creation as createClob() method threw error : java.lang.reflect.InvocationTargetException
二月 29, 2012 2:28:36 下午 org.hibernate.engine.transaction.internal.TransactionFactoryInitiator initiateService
INFO: HHH000399: Using default transaction strategy (direct JDBC transactions)
二月 29, 2012 2:28:36 下午 org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory <init>
INFO: HHH000397: Using ASTQueryTranslatorFactory
二月 29, 2012 2:28:36 下午 org.hibernate.tool.hbm2ddl.SchemaExport execute
INFO: HHH000227: Running hbm2ddl schema export
Hibernate:
drop table TB_USER cascade constraints
二月 29, 2012 2:28:37 下午 org.hibernate.tool.hbm2ddl.SchemaExport perform
ERROR: HHH000389: Unsuccessful: drop table TB_USER cascade constraints
二月 29, 2012 2:28:37 下午 org.hibernate.tool.hbm2ddl.SchemaExport perform
ERROR: ORA-00942: 表或视图不存在Hibernate:
drop sequence hibernate_sequence
二月 29, 2012 2:28:37 下午 org.hibernate.tool.hbm2ddl.SchemaExport perform
ERROR: HHH000389: Unsuccessful: drop sequence hibernate_sequence
二月 29, 2012 2:28:37 下午 org.hibernate.tool.hbm2ddl.SchemaExport perform
ERROR: ORA-02289: 序列不存在Hibernate:
create table TB_USER (
UID number(10,0) not null,
primary key (UID)
)
Hibernate:
create sequence hibernate_sequence
二月 29, 2012 2:28:37 下午 org.hibernate.tool.hbm2ddl.SchemaExport perform
ERROR: HHH000389: Unsuccessful: create table TB_USER (UID number(10,0) not null, primary key (UID))
二月 29, 2012 2:28:37 下午 org.hibernate.tool.hbm2ddl.SchemaExport perform
ERROR: ORA-00904: : 标识符无效二月 29, 2012 2:28:37 下午 org.hibernate.tool.hbm2ddl.SchemaExport execute
INFO: HHH000230: Schema export complete
Hibernate:
select
hibernate_sequence.nextval
from
dual
二月 29, 2012 2:28:37 下午 org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
WARN: SQL Error: 928, SQLState: 42000
二月 29, 2012 2:28:37 下午 org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
ERROR: ORA-00928: 缺失 SELECT 关键字Hibernate:
insert
into
TB_USER
(UID)
values
(?)
Exception in thread "main" org.hibernate.exception.SQLGrammarException: ORA-00928: 缺失 SELECT 关键字 at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:122)
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:125)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:110)
at org.hibernate.engine.jdbc.internal.proxy.AbstractStatementProxyHandler.continueInvocation(AbstractStatementProxyHandler.java:129)
at org.hibernate.engine.jdbc.internal.proxy.AbstractProxyHandler.invoke(AbstractProxyHandler.java:81)
at $Proxy10.executeUpdate(Unknown Source)
at org.hibernate.engine.jdbc.batch.internal.NonBatchingBatch.addToBatch(NonBatchingBatch.java:56)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2856)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3297)
at org.hibernate.action.internal.EntityInsertAction.execute(EntityInsertAction.java:88)
at org.hibernate.engine.spi.ActionQueue.execute(ActionQueue.java:362)
at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:354)
at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:275)
at org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:326)
at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:52)
at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1127)
at org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:325)
at org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.beforeTransactionCommit(JdbcTransaction.java:101)
at org.hibernate.engine.transaction.spi.AbstractTransactionImpl.commit(AbstractTransactionImpl.java:175)
at com.aga.entity.Test.main(Test.java:17)
Caused by: java.sql.SQLException: ORA-00928: 缺失 SELECT 关键字 at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:331)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:288)
at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:743)
at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:213)
at oracle.jdbc.driver.T4CPreparedStatement.executeForRows(T4CPreparedStatement.java:952)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1160)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3285)
at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:3368)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.hibernate.engine.jdbc.internal.proxy.AbstractStatementProxyHandler.continueInvocation(AbstractStatementProxyHandler.java:122)
... 16 more
错误,这属性不能来回改变?怎么会这样?我写的annotation头几次都能正常生成表,一把hbm2ddl从update改成create就报缺失 SELECT 关键字,以后就永远用不了。救命啊 影响进度
你先把表都drop掉,然后重新执行试试。