Spring + Hibernate confuguration

I am trying to integrate Spring and Hibernate but when I run the code and submit my for then it throws this exception 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] I found the reason on google but get stuckPlease guide me where I am wrong Here is applicationcontext.xml

<?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>

And here is 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> Here is my DAO class

@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;
    }
}

ANd this is my CRUD class

`@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 ......................... ");
 }
}`

This is my Entity Class

`@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

Answers


USER is a reserved keyword of your database. Use another name for your table.


Need Your Help

Extract text with regex between “,”

regex sequence

I have been struggling making a regex to extract the information in below divided in 3 part between the ",". Only the first and second sequence (Friday and the date has succeded).

Mongo Node JS is behaving differently on a 2nd AWS ECS instance

node.js mongodb amazon-web-services amazon-ec2

I have a NodeJS server, along with MongoDB, running on an AWS EC2 instance. I have replicated this instance and started up another one, but the behavior of the code is now different. What I mean by

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.