hibernateを使用してデータベースにオブジェクトを保存しようとしています。私は、新しいテーブル名と初めてのコードを実行すると、エラーの下に投げ、私は二回、それを実行するときには、ここで完全に微Hibernate - テーブルまたはビューdoes not existエラー
INFO: HHH10001501: Connection obtained from JdbcConnectionAccess [org.hibernate.engine.jdbc.env.internal.[email protected]61ce23ac] for (non-JTA) DDL execution was not in auto-commit mode; the Connection 'local transaction' will be committed and the Connection will be set into auto-commit mode.
Sep 01, 2016 3:51:18 AM org.hibernate.tool.schema.internal.ExceptionHandlerLoggedImpl handleException
WARN: GenerationTarget encountered exception accepting command : Error executing DDL via JDBC Statement
org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL via JDBC Statement
at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:62)
at org.hibernate.tool.schema.internal.SchemaDropperImpl.applySqlString(SchemaDropperImpl.java:374)
at org.hibernate.tool.schema.internal.SchemaDropperImpl.applySqlStrings(SchemaDropperImpl.java:359)
at org.hibernate.tool.schema.internal.SchemaDropperImpl.dropFromMetadata(SchemaDropperImpl.java:241)
at org.hibernate.tool.schema.internal.SchemaDropperImpl.performDrop(SchemaDropperImpl.java:154)
at org.hibernate.tool.schema.internal.SchemaDropperImpl.doDrop(SchemaDropperImpl.java:126)
at org.hibernate.tool.schema.internal.SchemaDropperImpl.doDrop(SchemaDropperImpl.java:112)
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:307)
at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:490)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:710)
at org.sf.main.SessionFactoryBuilder.getSessionFactory(SessionFactoryBuilder.java:26)
at org.sf.main.SessionFactoryBuilder.main(SessionFactoryBuilder.java:36)
Caused by: java.sql.SQLSyntaxErrorException: ORA-00942: table or view does not exist
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:447)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:396)
at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:951)
at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:513)
at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:227)
at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:531)
at oracle.jdbc.driver.T4CStatement.doOall8(T4CStatement.java:195)
at oracle.jdbc.driver.T4CStatement.executeForRows(T4CStatement.java:1036)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1336)
at oracle.jdbc.driver.OracleStatement.executeInternal(OracleStatement.java:1916)
at oracle.jdbc.driver.OracleStatement.execute(OracleStatement.java:1878)
at oracle.jdbc.driver.OracleStatementWrapper.execute(OracleStatementWrapper.java:318)
at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:49)
... 13 more
を働く私のコード - が
public static SessionFactory getSessionFactory() {
Configuration configuration = new Configuration();
configuration.setProperty("hibernate.hbm2ddl.auto", "create");
configuration.setProperty("hibernate.dialect", "org.hibernate.dialect.Oracle10gDialect");
configuration.setProperty("hibernate.connection.driver_class", "oracle.jdbc.driver.OracleDriver");
configuration.setProperty("hibernate.connection.url", "jdbc:oracle:thin:@somehost:1521:orcl");
configuration.setProperty("hibernate.connection.username", "username");
configuration.setProperty("hibernate.connection.password", "password");
configuration.setProperty("show_sql", "true");
configuration.setProperty("hibernate.default_schema", "somechema");
configuration.setPhysicalNamingStrategy(new HelloWorldNamingStrategy());
configuration.addAnnotatedClass(Census2010.class);
StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties());
SessionFactory sessionFactory = configuration.buildSessionFactory(builder.build());
return sessionFactory;
}
public static void main (String[] args) {
Census2010 obj = new Census2010();
obj.setData(100000L);
obj.setVariable("Population");
SessionFactory factory = getSessionFactory();
Session session = factory.openSession();
session.beginTransaction();
session.save(obj);
session.getTransaction().commit();
factory.close();
}
ですここに私のエンティティは、ここで
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table
public class Census2010 {
@Id
@Column(name="VARIABLE")
private String variable;
@Column(name="DATA")
private long data;
public String getVariable() {
return variable;
}
public void setVariable(String variable) {
this.variable = variable;
}
public long getData() {
return data;
}
public void setData(long data) {
this.data = data;
}
}
をクラス - さNamingStrategyをは
import org.hibernate.boot.model.naming.Identifier;
import org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl;
import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;
public class HelloWorldNamingStrategy extends PhysicalNamingStrategyStandardImpl {
private static final long serialVersionUID = 1L;
private static final String tableName = "A_12345_P";
@Override
public Identifier toPhysicalTableName(Identifier name, JdbcEnvironment context) {
return new Identifier(tableName, true);
}
}
をクラス - されます
何か助けていただければ幸いです。
"show_sql"プロパティが "true"に設定されていて、エラーが "JDBCステートメントを使用してDDLを実行中にエラーが発生しました"というエラーがあります。ログから生成されたDDLを提供できますか?エンティティのテーブルのDDL文が例外の前に表示されます。 –