2013-04-28 1 views
2

이것은 내가 게시 한 첫 번째 질문이므로 모든 규칙이나 예의 범절을 위반하면 사전에 사과드립니다. 나는 다음과 같은 예외를 제거 할 수없는 것 :"명명 된 쿼리의 오류 : User.findByUserNameAndPassword"- 해결할 수 없음

Caused by: javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build EntityManagerFactory 
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:915) 
at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:74) 
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:257) 
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:310) 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1514) 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1452) 
... 79 more 

Caused by: org.hibernate.HibernateException: Errors in named queries: User.findByUserNameAndPassword 
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:426) 
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1872) 
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:906) 

내 명명 된 질의는 다음과 같습니다 가지고있는 엔티티 (! 나하려고)

@Entity 
@Table(name="USERS") 
@NamedQueries 
({ 
    @NamedQuery(name="User.findByUserNameAndPassword", query="SELECT u FROM User u WHERE u.username = :username AND u.password = :password") 
}) 
public class User implements Serializable { 
private static final long serialVersionUID = 1L; 

@Id 
@SequenceGenerator(name="USERS_ID_GENERATOR", sequenceName="PERSONAL.GLOBALSEQUENCE") 
@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="USERS_ID_GENERATOR") 
private long id; 

private String notes; 

@Column(name="PASSWORD") 
private String password; 



@Column(name="USERNAME") 
private String username; 
... 

내가 실행하고 UserServiceImpl 클래스에서이 쿼리 같은

:

@Transactional(readOnly=true) 
public User authenticate(String userName, String password) { 
    List<User> usersList = em.createQuery("User.findByUserNameAndPassword", User.class).setParameter("username", userName).setParameter("password", password).getResultList(); 
    User firstUserFromList = usersList.get(0); 
    return firstUserFromList; 
} 

내가 그럴 필요있다 많은 일들이 있었지만 잠시 동안이 일에 매달 렸습니다. 도움이나 안내는 정말 감사하겠습니다.

내 applicationContext.xml 파일은 다음과 같습니다

환호 :

<beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:jpa="http://www.springframework.org/schema/data/jpa" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jee="http://www.springframework.org/schema/jee" xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa-1.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.1.xsd"> <context:component-scan base-package="com.transience.sandbox" /> <mvc:annotation-driven /> <tx:annotation-driven /> <mvc:resources mapping="/static_resources/**" location="/static_resources/" /> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix"> <value>/WEB-INF/pages/</value> </property> <property name="suffix"> <value>.jsp</value> </property> </bean> <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"> <property name="entityManagerFactory" ref="emf"/> </bean> <bean id="emf" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> <property name="dataSource" ref="dataSource" /> <property name="jpaVendorAdapter"> <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" /></property> <property name="packagesToScan" value="com.transience.sandbox.domain"/> <property name="jpaProperties"> <props> <prop key="hibernate.query.factory_class">org.hibernate.hql.classic.ClassicQueryTranslatorFactory</prop> <prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop> <prop key="hibernate.max_fetch_depth">3</prop> <prop key="hibernate.jdbc.fetch_size">50</prop> <prop key="hibernate.jdbc.batch_size">10</prop> <prop key="hibernate.show_sql">true</prop> </props> </property> </bean> <jee:jndi-lookup id="dataSource" jndi-name="oracleXEDS"/> <jpa:repositories base-package="com.transience.sandbox.domain" entity-manager-factory-ref="emf" transaction-manager-ref="transactionManager"/> </beans>

내가 Spring (core, webmvc, context, orm, jdbc, tx) 3.1, Hibernate 3.6.8, Spring-data-jpa 1.2.0, Weblogic 12cOracleXE을 사용하고 있습니다. 그리고 메이븐.

+0

config xml 파일을 보시려면 – Stuart

+0

@pospeq, 정보가 –

+0

인 게시물을 수정했습니다 @ user1268189 이것을 해결할 수 있었습니까? 내가 거의 2 년 동안 이걸 붙잡힌 것 같아. 내 문제는 다음과 같습니다. https://groups.google.com/forum/#!topic/play-framework/F3wFUbSYIog Play 프레임 워크와 관련이 있지만 잘못했는지 잘 모르겠습니다. 이 문제를 해결할 수 있는지 알려주세요. – user1242321

답변

1

em.createQuery() 대신 em.createNamedQuery()을 사용해보세요.

+0

안녕 데이비드, 나는 다시 시도했다. (실제로는'em.createNamedQuery'로 시작했다.)하지만 아무런 변화가 없었다. 그래도 고마워. –

0

거의 초기 관찰 : 당신은 오라클에서 예약어 USER로 엔티티를 정의

. 따라서 쿼리 SELECT u FROM User u ...이 (가) 네이티브 쿼리로 변환되면 문제가 발생할 수 있습니다.

적절한 로깅 수준 &을 실행하여 생성 된 쿼리를 조사하십시오. 또한 예약어/키워드 사용을 피하십시오. & 더 의미있는 규칙을 지정하십시오.

+0

같은 쿼리는 다음과 같이 서비스 구현 클래스'UserServiceImpl' 내에 정의 될 때 작동합니다 :'private static final String QUERY_FINDBYUSERNAMEANDPASSWORD = "사용자 u에서 u를 선택하십시오. u.username = : username 및 u.password = : password"; 또한, NamedQuery를 사용하면 WLS에 응용 프로그램을 배포 할 수도 없습니다. –

+0

@ user1268189 NamedQuery는 배포시 유효성이 검사되므로 배포시 문제가 발생하면 문제가 발생합니다. –

관련 문제