で既に利用されているとして、マッピング・ドキュメントをマップすることができませんconfiguration.cfg.xml休止状態:ここで彼らは
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost:3306/hibernate_xml</property>
<property name="connection.username">root</property>
<property name="connection.password">root</property>
<property name="show_sql">true</property>
<property name="hbm2ddl.auto">create</property>
<property name="format_sql">true</property>
<!-- mapping configurations -->
<mapping resource="resources/Employee.hbm.xml" />
<mapping resource="resources/Department.hbm.xml" />
</session-factory>
</hibernate-configuration>
は私Employee.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.domain.Employee" table="employee">
<id name="id" type="long" column="id">
<generator class="increment" />
</id>
<property name="firstName" name="firstName" />
<property name="salary" name="salary" />
<many-to-one name="department" class="com.domain.Department">
<column name="department" />
</many-to-one>
</class>
</hibernate-mapping>
department.hbm.xml
です<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.domain.Department" table="department">
<id name="id" type="long" column="id">
<generator class="auto" />
</id>
<property name="deptName" column="deptName" />
</class>
</hibernate-mapping>
セッションファクトリー
public static SessionFactory getSessionFactory() {
SessionFactory sessionFactory = null;
try {
sessionFactory = new Configuration().configure("resources/configuration.cfg.xml")
.addResource("resources/Employee.hbm.xml").addResource("resources/Department.hbm.xml")
.buildSessionFactory();
} catch (Throwable ex) {
throw new ExceptionInInitializerError(ex);
}
return sessionFactory;
}
、最終的には例外
スレッドの例外 com.utility.HibernateUtil.getSessionFactory(HibernateUtil.java:15)で "メイン" java.lang.ExceptionInInitializerErrorで com.client.Client.getTransaction(Client.java:13)at com.client.Client.main(Client.java:32)原因: org.hibernate.boot.InvalidMappingException:マッピングを解析できませんでした 文書:resources/Employee.hbm.xml(RESOURCE)at org.hibernate.boot.jaxb.internal.InputStreamXmlSource.doBind(InputStreamXmlSource.java:46) at org.hibernate.boot.jaxb.internal.UrlXmlSource。 doBind org.hibernate.boot.MetadataSources.addResource(MetadataSources.java:274)で org.hibernate.boot.spi.XmlMappingBinderAccess.bind(XmlMappingBinderAccess.java:59)で(UrlXmlSource.java:36) で org.hibernate.cfg.Configuration.addResource(Configuration.java:498) com.utility.HibernateUtil.getSessionFactory(HibernateUtil.java:12) ... 2他に発生したもの:org.hibernate.boot.MappingException: Unlock to pe rformは行番号0と列0でアンマーシャリングします。メッセージ:null: 起源(resources/Employee.hbm.xml): org.hibernate.boot.jaxb.internal.AbstractBinder.jaxb(AbstractBinder.java:177) at org.hibernate.boot.jaxb.internal.MappingBinder.doBind(MappingBinder.java:61) でorg.hibernate.boot.jaxb.internal.AbstractBinder.doBind(AbstractBinder.java:102) org.hibernateで。 (JavaBeans).Bind.jaxb.internal.AbstractBinder.bind(AbstractBinder.java:57) at org.hibernate.boot.jaxb.internal.InputStreamXmlSource.doBind(InputStreamXmlSource.java:43) ... 7より原因:javax。 xml.bind.UnmarshalException - リンク例外あり:[javax.xml 。ストリーム.XMLStreamException:[行、列]でParseError:[10,49]メッセージ: http://www.w3.org/TR/1999/REC-xml-names-19990114#AttributeNotUnique?property&name] com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.handleExceptionException(UnmarshallerImpl.java:470) でcom.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:448) com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImplで 。 unmarshal(UnmarshallerImpl.java:420) at org.hibernate.boot.jaxb.internal.AbstractBinder.jaxb(AbstractBinder.java:171) ... 11より原因:javax.xml.stream。XMLStreamException:で ParseErrorです[行、列]:[10,49]メッセージ: com.sun.org.apache.xerces.internal.impl.XMLStreamReaderImpl.next(XMLStreamReaderImpl.java:596)で http://www.w3.org/TR/1999/REC-xml-names-19990114#AttributeNotUnique?property&name を時com.sun.xml.internal.stream.XMLEventReaderImpl.peek javax.xml.stream.util.EventReaderDelegate.peek(EventReaderDelegate.java:104)で(XMLEventReaderImpl.java:276) org.hibernate.boot で。 org.hibernでjaxb.internal.stax.BufferedXMLEventReader.peek(BufferedXMLEventReader.java:96) でjavax.xml.stream.util.EventReaderDelegate.peek(EventReaderDelegate.java:104) (StAXEventConnector.java:164) com.sun.xml.internal.bind.v2.runtime.unmarshaller.StAXEventConnector.bridge(StAXEventConnector.java:126) at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0 (UnmarshallerImpl.java:445) ...もっと13
として、私は他のエラーで捕まってしまったそのエラーを解決した後、
Hibernate:
alter table employee
drop
foreign key FKkxx4wtsgsdt16iix2pso0k126
Sep 27, 2016 3:23:37 PM org.hibernate.tool.schema.internal.ExceptionHandlerLoggedImpl handleException
WARN: GenerationTarget encountered exception accepting command : Unable to execute command [
alter table employee
drop
foreign key FKkxx4wtsgsdt16iix2pso0k126]
org.hibernate.tool.schema.spi.CommandAcceptanceException: Unable to execute command [
alter table employee
drop
foreign key FKkxx4wtsgsdt16iix2pso0k126]
at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:63)
at org.hibernate.tool.schema.internal.SchemaDropperImpl.applySqlString(SchemaDropperImpl.java:370)
at org.hibernate.tool.schema.internal.SchemaDropperImpl.applySqlStrings(SchemaDropperImpl.java:355)
at org.hibernate.tool.schema.internal.SchemaDropperImpl.applyConstraintDropping(SchemaDropperImpl.java:327)
at org.hibernate.tool.schema.internal.SchemaDropperImpl.dropFromMetadata(SchemaDropperImpl.java:229)
at org.hibernate.tool.schema.internal.SchemaDropperImpl.performDrop(SchemaDropperImpl.java:153)
at org.hibernate.tool.schema.internal.SchemaDropperImpl.doDrop(SchemaDropperImpl.java:125)
at org.hibernate.tool.schema.internal.SchemaDropperImpl.doDrop(SchemaDropperImpl.java:111)
at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.performDatabaseAction(SchemaManagementToolCoordinator.java:137)
at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.process(SchemaManagementToolCoordinator.java:65)
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:308)
at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:483)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:707)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:723)
at com.utility.HibernateUtil.getSessionFactory(HibernateUtil.java:13)
at com.client.Client.getTransaction(Client.java:13)
at com.client.Client.main(Client.java:32)
Caused by: com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: Table 'hibernate_xml.employee' doesn't exist
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:936)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2985)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1631)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1723)
at com.mysql.jdbc.Connection.execSQL(Connection.java:3277)
at com.mysql.jdbc.Connection.execSQL(Connection.java:3206)
at com.mysql.jdbc.Statement.execute(Statement.java:727)
at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:51)
... 16 more
Hibernate:
drop table if exists department
Hibernate:
drop table if exists employee
Hibernate:
create table department (
id bigint not null,
deptName varchar(255),
primary key (id)
)
Hibernate:
create table employee (
id bigint not null,
firstName varchar(255),
salary double precision,
department bigint,
primary key (id)
)
Hibernate:
alter table employee
add constraint FKkxx4wtsgsdt16iix2pso0k126
foreign key (department)
references department (id)
Sep 27, 2016 3:23:38 PM org.hibernate.tool.schema.internal.SchemaCreatorImpl applyImportSources
INFO: HHH000476: Executing import script 'org.hiber[email protected]bd06ca'
department saved with id : 0
Hibernate:
select
max(id)
from
employee
employee saved with id 1
Sep 27, 2016 3:23:39 PM org.hibernate.internal.ExceptionMapperStandardImpl mapManagedFlushFailure
ERROR: HHH000346: Error during managed flush [org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance beforeQuery flushing: com.domain.Department]
Exception in thread "main" java.lang.IllegalStateException: org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance beforeQuery flushing: com.domain.Department
at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:144)
at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:155)
at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:162)
at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1403)
at org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:473)
at org.hibernate.internal.SessionImpl.flushBeforeTransactionCompletion(SessionImpl.java:3133)
at org.hibernate.internal.SessionImpl.beforeTransactionCompletion(SessionImpl.java:2370)
at org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl.beforeTransactionCompletion(JdbcCoordinatorImpl.java:467)
at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl.beforeCompletionCallback(JdbcResourceLocalTransactionCoordinatorImpl.java:146)
at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl.access$100(JdbcResourceLocalTransactionCoordinatorImpl.java:38)
at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl$TransactionDriverControlImpl.commit(JdbcResourceLocalTransactionCoordinatorImpl.java:220)
at org.hibernate.engine.transaction.internal.TransactionImpl.commit(TransactionImpl.java:68)
at com.client.Client.getTransaction(Client.java:27)
at com.client.Client.main(Client.java:32)
Caused by: org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance beforeQuery flushing: com.domain.Department
at org.hibernate.engine.internal.ForeignKeys.getEntityIdentifierIfNotUnsaved(ForeignKeys.java:279)
at org.hibernate.type.EntityType.getIdentifier(EntityType.java:462)
at org.hibernate.type.ManyToOneType.isDirty(ManyToOneType.java:298)
at org.hibernate.type.ManyToOneType.isDirty(ManyToOneType.java:309)
at org.hibernate.type.TypeHelper.findDirty(TypeHelper.java:296)
at org.hibernate.persister.entity.AbstractEntityPersister.findDirty(AbstractEntityPersister.java:4139)
at org.hibernate.event.internal.DefaultFlushEntityEventListener.dirtyCheck(DefaultFlushEntityEventListener.java:528)
at org.hibernate.event.internal.DefaultFlushEntityEventListener.isUpdateNecessary(DefaultFlushEntityEventListener.java:215)
at org.hibernate.event.internal.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:142)
at org.hibernate.event.internal.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:216)
at org.hibernate.event.internal.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:85)
at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:38)
at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1397)
... 10 more
すべてが適切な場合にこのエラーが発生する理由はわかりません。
<property name="firstName" column="firstName"/>
<property name="salary" column="firstName" />
:
Employee.hbm.xmlのname属性がすでに(2回/複製使用)が指定されている
おかげで、あなたは気にしないならば、それは –
[OK]を、とのご質問を更新してください...他のエラーに私を導きました他のエラー。 –
私は編集部 –