2016-05-18 5 views
1

私は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 
+0

TEST_MONTHSテーブルのTEST_CODE列の存在はありますか? – Saravana

+0

TEST_MONTHSテーブルに列TEST_CODEが存在しないというエラーが表示されます。同じ列名がデータベースに存在することを確認してください。 – ypp

+0

スキーマを投稿してください。 – Thanga

答えて

0

できますか?一体SQLでテーブルの詳細は、それはそれで、私は

CREATE TABLE `orders` (
`id` INT NOT NULL PRIMARY KEY AUTO_INCREMENT, 
`firstname` VARCHAR(50) NOT NULL, 
); 

以下のように表の詳細を持っていたと私はだった、私のコードでは、私も直面した同じ問題として、その周りに引用符または単一引用符

を「」持っています単一引用符を除去した後、豆

@Entity 
@Table(name="orders") 
public class Order { 

    @Id 
    @GeneratedValue 
    @Column(name="id") 
    private int id; 

    @Column(name="firstname") 
    private String firstName; 

    @OneToMany(targetEntity=OrderLine.class, 
      cascade = CascadeType.ALL, 
      fetch = FetchType.LAZY) 
    @JoinTable(
      name="orderlines", 
      joinColumns = {@JoinColumn(table = "orderlines", name="FK_orders_orders", 
      referencedColumnName = "order_id")}, 
      inverseJoinColumns={@JoinColumn(table = "orders", name="FK_orders_orders", 
      referencedColumnName = "id")} 
      ) 

の下でそれにアクセスするには、それは私のために働き始め

+0

sqlがテーブル/カラム名を引用していないことを確認しました。私は、エディタでDDLを生成することを確認しました – Ramkumar

+0

あなたのデータベース上に表示されているかどうかを調べるために私のコードの上で試してみることができます –

+0

私はdidntを残念申し訳ありません。 – Ramkumar

関連する問題