2013-05-05 2 views
0

간단한 봄 보안 최대 절전 모드 로그인 응용 프로그램을 구축하려고합니다. 하지만 최대 절전 모드로 데이터베이스에서 결과를 가져 오는 데 문제가 있습니다. 다음은 쿼리 할 Service 클래스입니다.봄, 최대 절전 모드 데이터베이스 쿼리

UserAccountService :

package main.java.services; 

import javax.persistence.EntityManager; 
import javax.persistence.PersistenceContext; 
import javax.persistence.Query; 

import main.java.model.UserAccount; 

import org.springframework.stereotype.Service; 
import org.springframework.transaction.annotation.Transactional; 

@Service("userAccountService") 
@Transactional 
public class UserAccountService { 

    private EntityManager entityManager; 

    @PersistenceContext 
    public void setEntityManager(EntityManager entityManager){ 
      this. entityManager = entityManager; 
     } 
    public UserAccount get(Integer id) 
    { 
     String sql = "FROM UserAccount as ua WHERE ua.id="+id; 
     Query query = entityManager.createQuery(sql); 
     return (UserAccount) query.getSingleResult(); 
    } 

    public UserAccount get(String username) 
    { 
     String sql = "FROM UserAccount WHERE username='"+username+"'"; 
     System.out.println("test1"); 
     Query query = entityManager.createQuery(sql); 
     System.out.println("test2"); 
     System.out.println(query.getSingleResult()); 
     return (UserAccount) query.getSingleResult(); 
    } 

    public void add(UserAccount userAccount) 
    { 
     entityManager.persist(userAccount); 
    } 
} 

내 문제는 코드가 "TEST1"를 도달 할 것입니다, 그러나 "TEST2"를 도달 할 것이며, 그것이 나에게 오류를 표시하지 않습니다. 나는 네이티브 질의를 시도했지만, 그때까지 콘솔에 최대 절전 모드를 가져올 것이다.하지만 여전히 내 반환 값은 0이다.하지만 나에게 UserAccount 객체를 리턴해야한다. 기본 쿼리 콘솔 쇼와 함께이 "최대 절전 모드 : USER_ACCOUNT FROM = '뭔가'이름 WHERE"나야 다음은 데이터베이스 내 conf의 파일입니다 :

HibernateContext.xml

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" 
     xmlns:p="http://www.springframework.org/schema/p" 
     xsi:schemaLocation="http://www.springframework.org/schema/beans 
     http://www.springframework.org/schema/beans/spring-beans.xsd 
     http://www.springframework.org/schema/context 
     http://www.springframework.org/schema/context/spring-context-3.1.xsd 
     http://www.springframework.org/schema/tx 
     http://www.springframework.org/schema/tx/spring-tx-3.1.xsd"> 

    <context:property-placeholder location="/WEB-INF/jdbc.properties" /> 

    <tx:annotation-driven transaction-manager="transactionManager" /> 

    <!-- Declare a datasource that has pooling capabilities--> 
    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" 
      destroy-method="close" 
      p:driverClass="${jdbc.driverClassName}" 
      p:jdbcUrl="${jdbc.url}" 
      p:user="${jdbc.username}" 
      p:password="${jdbc.password}" 
      p:acquireIncrement="5" 
      p:idleConnectionTestPeriod="60" 
      p:maxPoolSize="100" 
      p:maxStatements="50" 
      p:minPoolSize="10" /> 

    <!-- Declare a JPA entityManagerFactory--> 
    <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" > 
     <property name="persistenceXmlLocation" value="classpath*:META-INF/persistence.xml"></property> 
     <property name="persistenceUnitName" value="hibernatePersistenceUnit" /> 
     <property name="dataSource" ref="dataSource"/> 
     <property name="jpaVendorAdapter"> 
      <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" > 
       <property name="databasePlatform"> 
        <value>${jdbc.dialect}</value> 
       </property> 
       <property name="showSql" value="true"/> 
      </bean> 
     </property> 
    </bean> 

    <!-- Declare a transaction manager--> 
    <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"> 
     <property name="entityManagerFactory" ref="entityManagerFactory" /> 
    </bean> 

</beans> 

답변

0

실행 x하지만 라인을 일렬로 들어갔을 경우 x+2 다음 줄 x+1은 예외를 발생 시키거나 무기한 차단/루핑, 스레드 강제 종료 또는 VM exit 루틴 호출이되어야합니다.

이 중 가장 많이 발생하는 것은 예외를 발생시키는 것입니다. 오류가 표시되지 않는 경우, 당신은 아마 같은 예외를 삼키는 것 코드가 있습니다

try { 
    ... 
} catch { 
    // Ignore exception 
} 

어느 쪽이든을, 또는 가능성이 어딘가에 기록 점점하고 로그를 찾고 아닙니다. 자세한 내용은 응용 프로그램 서버 로그를 확인하십시오. 사용중인 앱 서버에 대해 언급하지 않았으므로 이에 대해 더 구체적으로 설명 할 수 없습니다.

그런 식으로 문제를 식별 할 수없는 경우 디버거를 응용 프로그램에 연결하십시오 (예, 응용 프로그램이 컨테이너/응용 프로그램 서버에서 실행될 때 가능함). 마지막으로 알려진 OK 문에서 중단 점을 설정 한 다음 코드를 단계별로 실행하여 상황을 확인합니다.

+0

try catch 블록을 추가하면 "UserAccount가 [UserAccount uu.username = : username]에 매핑되지 않았습니다."라는 오류 메시지가 표시됩니다.이 오류를 지금 어떻게 수정해야할지 확실하지 않습니다. D – Kapaacius