私はHibernateプロジェクトをSpring Hibernate Projectに変換しています。私はSpringとHibernateを統合しているので、@Configurationのすべてのセッションファクトリとデータソース定義を定義しています。展開した後、私は、サーバーを起動したとき、私は例外の下に取得していますorg.hibernate.MappingException:Spring Hibernateで論理名のカラムを見つけることができません
Unable to find column with logical name: TEST_CODE in org.hibernate.mapping.Table(TEST_MONTHS) and its related supertables and secondary tables.
EntityClass:
@javax.persistence.Entity
@Table(name="TEST_MONTHS")
public class ConnectionMonth implements Serializable {
/**
* @generated
*/
private static final long serialVersionUID = -940496855L;
@Id
@Column(name = "TEST_CODE")
private String testCode;
@Id
@Column(name = "CONMONTH")
private String contractMonth;
@Column(name = "TYPE")
private String type;
@Column(name = "STARTDATE")
private Date startDate;
@Column(name = "ENDDATE")
private Date endDate;
public String gettestCode() {
return testCode;
}
public void settestCode(String testCode) {
this.testCode = testCode;
}
public String getContractMonth() {
return contractMonth;
}
public void setContractMonth(String contractMonth) {
this.contractMonth = contractMonth;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public Date getStartDate() {
return startDate;
}
public void setStartDate(Date startDate) {
this.startDate = startDate;
}
public Date getEndDate() {
return endDate;
}
public void setEndDate(Date endDate) {
this.endDate = endDate;
}
/**
* @generated
*/
@Override
public String toString() {
return "ContractMonth: " + contractMonth + " Type: " + type
+ " StartDate: " + startDate + " EndDate: " + endDate;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result
+ ((testCode == null) ? 0 : testCode.hashCode());
result = prime * result
+ ((contractMonth == null) ? 0 : contractMonth.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
ContractMonth other = (ContractMonth) obj;
if (testCode == null) {
if (other.testCode != null)
return false;
} else if (!testCode.equals(other.testCode))
return false;
if (contractMonth == null) {
if (other.contractMonth != null)
return false;
} else if (!contractMonth.equals(other.contractMonth))
return false;
return true;
}
}
永続設定:
@Configuration
@EnableTransactionManagement
@PropertySource({ "classpath:persistence.properties" })
@ComponentScan({ "com.test.commons.domain.*" })
public class PersistenceConfiguration {
@Autowired
private Environment env;
@Bean
public LocalSessionFactoryBean sessionFactory() {
LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean();
sessionFactory.setDataSource(restDataSource());
sessionFactory.setPackagesToScan(new String[] {
"com.test.commons.domain.employee"});
sessionFactory.setHibernateProperties(hibernateProperties());
return sessionFactory;
}
@Bean
public DataSource restDataSource() {
BasicDataSource dataSource = new BasicDataSource();
dataSource.setDriverClassName(env.getProperty("jdbc.driverClassName"));
dataSource.setUrl(env.getProperty("jdbc.url"));
dataSource.setUsername(env.getProperty("jdbc.user"));
dataSource.setPassword(env.getProperty("jdbc.pass"));
return dataSource;
}
@Bean
@Autowired
public HibernateTransactionManager transactionManager(
SessionFactory sessionFactory) {
HibernateTransactionManager txManager = new HibernateTransactionManager();
txManager.setSessionFactory(sessionFactory);
return txManager;
}
@Bean
public PersistenceExceptionTranslationPostProcessor exceptionTranslation() {
return new PersistenceExceptionTranslationPostProcessor();
}
Properties hibernateProperties() {
return new Properties() {
{
setProperty("hibernate.hbm2ddl.auto",
env.getProperty("hibernate.hbm2ddl.auto"));
setProperty("hibernate.dialect",
env.getProperty("hibernate.dialect"));
setProperty("hibernate.globally_quoted_identifiers", "true");
}
};
}
}
persistence.properties:
# jdbc.X
jdbc.driverClassName=oracle.jdbc.driver.OracleDriver
jdbc.url=/*DB url*/
jdbc.user=pwd
jdbc.pass=pwd
# hibernate.X
hibernate.dialect=org.hibernate.dialect.OracleDialect
hibernate.show_sql=false
hibernate.hbm2ddl.auto=create-drop
TEST_MONTHSテーブルのTEST_CODE列の存在はありますか? – Saravana
TEST_MONTHSテーブルに列TEST_CODEが存在しないというエラーが表示されます。同じ列名がデータベースに存在することを確認してください。 – ypp
スキーマを投稿してください。 – Thanga