2013-09-09 2 views
1

나는 이클립스에서 알 수없는 엔티티 문제를 해결하기 위해 하루 종일 노력하고있다. 별도의 .java 및 hbm.xml 파일을 사용하고 있습니다.Hibernate Eclipse 알 수없는 엔티티 (javax.persistence.Entity 사용)

내 엔티티 클래스는 Account.java

// default package 
package com.mywebservice.domain; 
// Generated Sep 9, 2013 3:55:42 PM by Hibernate Tools 3.4.0.CR1 

import java.util.Date; 
import javax.persistence.Entity; 

/** 
* Account generated by hbm2java 
*/ 


public class Account implements java.io.Serializable { 

    private int id; 
    private String uid; 
    private String empId; 
    private String password; 
    private Integer status; 
    private Integer roleId; 
    private String name; 
    private String description; 
    private String details; 
    private String email; 
    private Date dateCreated; 
    private Date dateModified; 
    private String modifiedBy; 
    private Integer efpRoleId; 
    private Integer isEfp; 
    private Integer deptId; 
    private Boolean isEpp; 
    private Boolean isPasswordNew; 
    private Integer statusEpp; 

    public Account() { 
    } 

    public Account(int id) { 
     this.id = id; 
    } 

    public Account(int id, String uid, String empId, String password, 
      Integer status, Integer roleId, String name, String description, 
      String details, String email, Date dateCreated, Date dateModified, 
      String modifiedBy, Integer efpRoleId, Integer isEfp, 
      Integer deptId, Boolean isEpp, Boolean isPasswordNew, 
      Integer statusEpp) { 
     this.id = id; 
     this.uid = uid; 
     this.empId = empId; 
     this.password = password; 
     this.status = status; 
     this.roleId = roleId; 
     this.name = name; 
     this.description = description; 
     this.details = details; 
     this.email = email; 
     this.dateCreated = dateCreated; 
     this.dateModified = dateModified; 
     this.modifiedBy = modifiedBy; 
     this.efpRoleId = efpRoleId; 
     this.isEfp = isEfp; 
     this.deptId = deptId; 
     this.isEpp = isEpp; 
     this.isPasswordNew = isPasswordNew; 
     this.statusEpp = statusEpp; 
    } 

    public int getId() { 
     return this.id; 
    } 

    public void setId(int id) { 
     this.id = id; 
    } 

    public String getUid() { 
     return this.uid; 
    } 

    public void setUid(String uid) { 
     this.uid = uid; 
    } 

    public String getEmpId() { 
     return this.empId; 
    } 

    public void setEmpId(String empId) { 
     this.empId = empId; 
    } 

    public String getPassword() { 
     return this.password; 
    } 

    public void setPassword(String password) { 
     this.password = password; 
    } 

    public Integer getStatus() { 
     return this.status; 
    } 

    public void setStatus(Integer status) { 
     this.status = status; 
    } 

    public Integer getRoleId() { 
     return this.roleId; 
    } 

    public void setRoleId(Integer roleId) { 
     this.roleId = roleId; 
    } 

    public String getName() { 
     return this.name; 
    } 

    public void setName(String name) { 
     this.name = name; 
    } 

    public String getDescription() { 
     return this.description; 
    } 

    public void setDescription(String description) { 
     this.description = description; 
    } 

    public String getDetails() { 
     return this.details; 
    } 

    public void setDetails(String details) { 
     this.details = details; 
    } 

    public String getEmail() { 
     return this.email; 
    } 

    public void setEmail(String email) { 
     this.email = email; 
    } 

    public Date getDateCreated() { 
     return this.dateCreated; 
    } 

    public void setDateCreated(Date dateCreated) { 
     this.dateCreated = dateCreated; 
    } 

    public Date getDateModified() { 
     return this.dateModified; 
    } 

    public void setDateModified(Date dateModified) { 
     this.dateModified = dateModified; 
    } 

    public String getModifiedBy() { 
     return this.modifiedBy; 
    } 

    public void setModifiedBy(String modifiedBy) { 
     this.modifiedBy = modifiedBy; 
    } 

    public Integer getEfpRoleId() { 
     return this.efpRoleId; 
    } 

    public void setEfpRoleId(Integer efpRoleId) { 
     this.efpRoleId = efpRoleId; 
    } 

    public Integer getIsEfp() { 
     return this.isEfp; 
    } 

    public void setIsEfp(Integer isEfp) { 
     this.isEfp = isEfp; 
    } 

    public Integer getDeptId() { 
     return this.deptId; 
    } 

    public void setDeptId(Integer deptId) { 
     this.deptId = deptId; 
    } 

    public Boolean getIsEpp() { 
     return this.isEpp; 
    } 

    public void setIsEpp(Boolean isEpp) { 
     this.isEpp = isEpp; 
    } 

    public Boolean getIsPasswordNew() { 
     return this.isPasswordNew; 
    } 

    public void setIsPasswordNew(Boolean isPasswordNew) { 
     this.isPasswordNew = isPasswordNew; 
    } 

    public Integer getStatusEpp() { 
     return this.statusEpp; 
    } 

    public void setStatusEpp(Integer statusEpp) { 
     this.statusEpp = statusEpp; 
    } 

} 

되고 Account.hbm.xml 내가 폴더의 유틸리티 내 세션 공장을 만들

package com.mywebservice.utils; 

import org.hibernate.Session; 
import org.hibernate.SessionFactory; 
import org.hibernate.cfg.AnnotationConfiguration; 
import org.hibernate.cfg.Configuration; 

public class SessionFactoryUtil { 

    private static final SessionFactory sessionFactory; 

    static { 
     try { 
      // Create the SessionFactory from hibernate.cfg.xml 

      //Configuration config = new Configuration(); 
      Configuration config = new AnnotationConfiguration(); 
      sessionFactory = config.configure().buildSessionFactory(); 
     } catch (Throwable ex) { 
      // Make sure you log the exception, as it might be swallowed 
      System.err.println("Initial SessionFactory creation failed." + ex); 
      throw new ExceptionInInitializerError(ex); 
     } 
    } 

    public static SessionFactory getSessionFactory() { 
     return sessionFactory; 
    } 

} 

및 호출하고

<?xml version="1.0"?> 
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" 
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> 
<!-- Generated Sep 9, 2013 3:55:42 PM by Hibernate Tools 3.4.0.CR1 --> 
<hibernate-mapping> 
    <class name="Account" table="ACCOUNT" schema="dbo" catalog="EPP"> 
     <id name="id" type="int"> 
      <column name="ID" /> 
      <generator class="assigned" /> 
     </id> 
     <property name="uid" type="string"> 
      <column name="UID" length="50" /> 
     </property> 
     <property name="empId" type="string"> 
      <column name="EMP_ID" length="50" /> 
     </property> 
     <property name="password" type="string"> 
      <column name="PASSWORD" length="50" /> 
     </property> 
     <property name="status" type="java.lang.Integer"> 
      <column name="STATUS" /> 
     </property> 
     <property name="roleId" type="java.lang.Integer"> 
      <column name="ROLE_ID" /> 
     </property> 
     <property name="name" type="string"> 
      <column name="NAME" length="50" /> 
     </property> 
     <property name="description" type="string"> 
      <column name="DESCRIPTION" length="50" /> 
     </property> 
     <property name="details" type="string"> 
      <column name="DETAILS" length="50" /> 
     </property> 
     <property name="email" type="string"> 
      <column name="EMAIL" length="50" /> 
     </property> 
     <property name="dateCreated" type="timestamp"> 
      <column name="DATE_CREATED" length="23" /> 
     </property> 
     <property name="dateModified" type="timestamp"> 
      <column name="DATE_MODIFIED" length="23" /> 
     </property> 
     <property name="modifiedBy" type="string"> 
      <column name="MODIFIED_BY" length="50" /> 
     </property> 
     <property name="efpRoleId" type="java.lang.Integer"> 
      <column name="EFP_ROLE_ID" /> 
     </property> 
     <property name="isEfp" type="java.lang.Integer"> 
      <column name="IS_EFP" /> 
     </property> 
     <property name="deptId" type="java.lang.Integer"> 
      <column name="DEPT_ID" /> 
     </property> 
     <property name="isEpp" type="java.lang.Boolean"> 
      <column name="IS_EPP" /> 
     </property> 
     <property name="isPasswordNew" type="java.lang.Boolean"> 
      <column name="IS_PASSWORD_NEW" /> 
     </property> 
     <property name="statusEpp" type="java.lang.Integer"> 
      <column name="STATUS_EPP" /> 
     </property> 
    </class> 
</hibernate-mapping> 

입니다 그것 from

package com.mywebservice.utils; 

import org.hibernate.Session; 
import org.hibernate.Query; 
import com.mywebservice.domain.*; 
import org.hibernate.annotations.*; 

public class HibernateTest { 

    public static void main(String[] args) { 
     // TODO Auto-generated method stub 

     Session session = SessionFactoryUtil.getSessionFactory().getCurrentSession(); 
     session.beginTransaction(); 
     getAccount(session); 

    } 

    public static void getAccount(Session session) { 
     Account acc = new Account(); 

     acc.setEmpId("123456789"); 

     session.save(acc); 

     System.out.println("Saved!"); 
    } 

} 

또한, 나는 내 hibernate.cfg.xml로

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE hibernate-configuration PUBLIC 
     "-//Hibernate/Hibernate Configuration DTD 3.0//EN" 
     "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> 
<hibernate-configuration> 
    <session-factory> 
     <property name="hibernate.connection.driver_class">com.microsoft.sqlserver.jdbc.SQLServerDriver</property> 
     <property name="hibernate.connection.username">sa</property> 
     <property name="hibernate.connection.password">[email protected]</property> 
     <property name="hibernate.connection.url">jdbc:sqlserver://HQ-10063332D\SQLEXPRESS;DatabaseName=EPP</property> 
<!--   <property name="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</property> --> 
     <property name="hibernate.dialect">org.hibernate.dialect.SQLServer2008Dialect</property>   

     <property name="hibernate.current_session_context_class">thread</property> 

     <mapping class="com.mywebservice.domain.Account" /> 
    </session-factory> 
</hibernate-configuration> 

하지만 여전히 행운의 클래스의 매핑을 추가했습니다. 실마리가 있습니까?

내가 사용하고 : 최대 절전 모드 3.5 JPA 2.0 이클립스 케플러

UPDATE를 : 내 완전한 오류 스택 추적

Exception in thread "main" org.hibernate.MappingException: Unknown entity: com.mywebservice.domain.Account 
    at org.hibernate.impl.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:706) 
    at org.hibernate.impl.SessionImpl.getEntityPersister(SessionImpl.java:1475) 
    at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:121) 
    at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:210) 
    at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:56) 
    at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:195) 
    at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:50) 
    at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:93) 
    at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:705) 
    at org.hibernate.impl.SessionImpl.save(SessionImpl.java:693) 
    at org.hibernate.impl.SessionImpl.save(SessionImpl.java:689) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) 
    at java.lang.reflect.Method.invoke(Unknown Source) 
    at org.hibernate.context.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:344) 
    at com.sun.proxy.$Proxy0.save(Unknown Source) 
    at com.mywebservice.utils.HibernateTest.getAccount(HibernateTest.java:24) 
    at com.mywebservice.utils.HibernateTest.main(HibernateTest.java:15) 
+0

'AnnotationConfiguration' (사용되지 않음)을 사용합니다. 어노테이션없이. 'org.hibernate.cfg.Configuration.configure()'없이'hibernate.cfg.xml'을 사용합니다. 편도를 선택하십시오, 두 가지 방법이 함께 작동하지 않습니다. –

답변

0

입니다 난 당신이 Hibernate 매핑의 package 속성을 누락 생각합니다. 이런 식으로, 당신의 hbm 파일에 뭔가를 매핑 부분을 업데이트하십시오 : com.mywebservice.domain.Account 될뿐 아니라 Account

+0

도 이랬다. 아직도 같은 오류 –

0

귀하의 Account 클래스는 패키지 com.mywebservice.domain에 konw, XML을 사용하여 bean을 설정하면 annotationConfiguration을 사용하여 세션을 빌드하는 이유는 어노테이션 구성으로 시도 할 수 있습니다. 효과가있을 수 있습니다.

+0

했지만 오류가 계속납니다. –

+0

전체 오류 스택 추적을 보여줍니다 –

+0

질문이 업데이트되었습니다.stack trace added –

0

내가 원하는해야 당신의 Account.hbm.xmlclass 이름 있도록

<hibernate-mapping package="com.mywebservice.domain"> 
+0

#jesse AnnotationConfiguration 객체를 사용하지 않으면 ""를 사용하려면 AnnotationConfiguration 인스턴스가 필요합니다. " –

0

내 질문에 답하는 것이므로 다른 사람에게 도움이 될 수 있습니다. 내 hibernate.cfg.xml 내에서

은 매핑에 같은, 내가 오류 을 가지고도 내있는 hibernate.cfg.xml을 수정 한 후

<mapping resource="com/mywebservice/domain/Account.hbm.xml"></mapping> 

대신

<mapping class="com.mywebservice.domain.Account" /> 

"수 없습니다해야 javassist.jar라는 라이브러리를 추가해야만하는 기본 tuplizer를 시작하십시오. 행운을 빌어 요.

관련 문제