2013-08-13 1 views
0

을 내가 Hibernate 매핑 문제에 직면했습니다 스택 추적 : ID 생성 전략을 해석 할 수는 ID 생성기 전략 해석 할 수있다 : xyzCustomIDGenerator

public class UserProfileCustomIDGenerator extends IdentityGenerator{ 

@Override 
public Serializable generate(SessionImplementor session, Object object) 
     throws HibernateException { 
    // TODO Auto-generated method stub 
     UserProfiles userProfile = (UserProfiles)object; 
     if(userProfile.getId() != 0){ 
      return userProfile.getId(); 
     }else{ 
      Serializable id = super.generate(session, object); 
      return id; 
     } 

} 

} 
:

Exception in thread "SpringOsgiExtenderThread-14" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactoryMTS' defined in OSGi resource[classpath:spring-beans.xml|bnd.id=288|bnd.sym=persistence]: Invocation of init method failed; nested exception is org.hibernate.MappingException: could not instantiate id generator [entity-name=com.db.model.UserProfiles] 
     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1422) 
     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:518) 
     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:455) 
     at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:293) 
     at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) 
     at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:290) 
     at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:192) 
     at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:567) 
     at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895) 
     at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.access$1600(AbstractDelegatedExecutionApplicationContext.java:69) 
     at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext$4.run(AbstractDelegatedExecutionApplicationContext.java:355) 
     at org.springframework.osgi.util.internal.PrivilegedUtils.executeWithCustomTCCL(PrivilegedUtils.java:85) 
     at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.completeRefresh(AbstractDelegatedExecutionApplicationContext.java:320) 
     at org.springframework.osgi.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor$CompleteRefreshTask.run(DependencyWaiterApplicationContextExecutor.java:132) 
     at java.lang.Thread.run(Thread.java:619) 
Caused by: org.hibernate.MappingException: could not instantiate id generator [entity-name=com.db.model.UserProfiles] 
     at org.hibernate.id.IdentifierGeneratorFactory.create(IdentifierGeneratorFactory.java:132) 
     at org.hibernate.mapping.SimpleValue.createIdentifierGenerator(SimpleValue.java:175) 
     at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:230) 
     at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1341) 
     at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:867) 
     at org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSessionFactory(LocalSessionFactoryBean.java:860) 
     at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:779) 
     at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:211) 
     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1479) 
     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1419) 
     ... 14 more 
Caused by: org.hibernate.MappingException: could not interpret id generator strategy: com.db.custom.id.generator.UserProfileCustomIDGenerator 
     at org.hibernate.id.IdentifierGeneratorFactory.getIdentifierGeneratorClass(IdentifierGeneratorFactory.java:151) 
     at org.hibernate.id.IdentifierGeneratorFactory.create(IdentifierGeneratorFactory.java:124) 
     ... 23 more 

내 손님 여러분 아이디 생성기 클래스처럼 보인다

나는 인터넷 검색을했지만 해결책을 얻을 수 없습니다. 실수 나 해결책이 있는지 알려 주시기 바랍니다. 감사합니다. .

답변

0

IdentityGenerator 대신 IdentifierGenerator을 시도하십시오.

+0

IdentifierGenerator를 구현하면 UserProfile Id가 설정되지 않은 경우 super.generate 메서드를 호출 할 수 없습니다. userProfileId가 명시 적으로 설정되지 않은 경우 기본 전략을 사용하려는 경우 클래스를 확장해야합니다. –