2013-05-02 8 views
0

내가 구글에 대한 이유를 찾았지만 내가 어디
나를 인도 해주십시오 박히이 예외
org.springframework.dao.InvalidDataAccessResourceUsageException: could not insert: [com.xgrid.evaltask.Entities.User]; SQL [insert into User (UserName, passwd, ID) values (?, ?, ?)]; nested exception is org.hibernate.exception.SQLGrammarException: could not insert: [com.xgrid.evaltask.Entities.User]
을 나는 봄과 최대 절전 모드를 통합하려고하지만 코드를 실행하고 내를 제출할 때 다음이 발생합니다 여기에 잘못된
는 applicationcontext.xml
봄 + 최대 절전 모드 confuguration

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

    <context:component-scan base-package="com.xgrid.evaltask"/> 


    <bean id="dataSource" 
      class="org.springframework.jdbc.datasource.DriverManagerDataSource" 
      p:driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver" 
      p:url="jdbc:sqlserver://DBURL:1433;databaseName=Test_DB" 
      p:username="sampleUser" 
      p:password="@123456asdfgh" /> 


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


<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean" 
     p:dataSource-ref="dataSource"  
     p:packagesToScan="com.xgrid.evaltask" 
     /> 

    <context:annotation-config /> 

    <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager" 
     p:sessionFactory-ref="sessionFactory" /> 

</beans> 

입니다 그리고 여기에 여기에있는 hibernate.cfg.xml
<hibernate-configuration> <session-factory> <property name="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</property> <!-- Enable this to see the SQL statements in the logs--> <property name="show_sql">true</property> <!-- This will drop our existing database and re-create a new one. Existing data will be deleted! --> <property name="hbm2ddl.auto">create</property> </session-factory> </hibernate-configuration>
내 DAO 클래스 0123입니다

@Repository("authorizeDao") 
public class AuthorizeDaoImpl implements AuthorizeDao { 

    @Autowired 
    HiberAdd hiberAdd; 

    @Override 
    public boolean doAuthorize(Authentication authentication) { 
     System.out.println("Name: " + authentication.getUserName()); 
     System.out.println("PW: " + authentication.getPassWord()); 
     User user = new User(); 
     user.setId(1212); 
     user.setName(authentication.getUserName()); 
     user.setPasswd(authentication.getPassWord()); 
     hiberAdd.add(user); 
     return true; 
    } 
} 

는이 내 CRUD 클래스

`@Service("hiberAdd") 
@Transactional 
public class HiberAdd { 

    @Resource(name="sessionFactory") 
private SessionFactory sessionFactory; 
    public void add(User user) { 


    // Retrieve session from Hibernate 
    Session session = sessionFactory.getCurrentSession(); 

    // Save 
     session.save(user); 
     System.out.println("Saved ......................... "); 
} 
}` 


`@Entity 
@Table(name="User") 
public class User implements Serializable{ 

    @Id 
    @Column(name="ID") 
    private Integer id; 

    @Column(name="UserName") 
    private String name; 

    @Column(name="passwd") 
    private String passwd; 
//getters setters 
+0

사용자 테이블 구조 란 무엇입니까? –

+0

ID (int), 이름 (varchar), 암호 (varchar) – Despicable

+0

더 많은 오류 메시지를 붙여 넣을 수 있습니까? –

답변

1

USER이 데이터베이스의 reserved keyword 내 엔티티 클래스
입니다. 테이블에 다른 이름을 사용하십시오.

+0

예 downvoter 이유를 지정해야합니다. 어쨌든 내가 테이블 이름을 바꿔야한다는 뜻이야? 좋아, 시도해 보자 :) – Despicable

+0

네가 맞다 :) 아프다. :) 지금 삽입 중이다.하지만 분명히 나에게 한 가지만 알려주기 바란다. 단지 테이블이 이미 생성되었을 때만 데이터를 삽입하는 것이다. 하이버 네이트는 테이블을 생성하지 않는다. 왜 그런 일이 일어나는거야? – Despicable

+0

최대 절전 모드는 ORM입니다. 테이블을 만드는 것이 업무가 아닙니다. 그것은 * 할 수 있지만 특정 hibernate 속성 (hibernate.hbm2ddl.auto)을 설정 한 경우에만 가능합니다. 자세한 내용은이 속성에 대한 설명서를 검색하십시오. –

관련 문제