0

I am new in spring mvc and i am trying to make db table using annotation. but it is not creating when i use hbm.xml it works properly. Please help me. any help will be appriciable.

My form coding is:-

    import javax.persistence.Entity;
    import javax.persistence.GeneratedValue;
    import javax.persistence.GenerationType;
    import javax.persistence.Id;
    import javax.persistence.Table;
    import javax.validation.constraints.Size;
    import org.hibernate.validator.constraints.NotEmpty;
    @Entity
    @Table(name = "LOGIN_MASTER")
    public class LoginForm {
        @Id
        @GeneratedValue(strategy = GenerationType.AUTO)
        private long Id;
        @NotEmpty
        @Size(min = 1, max = 50)
        @Column(name = "userName")
        private String userName;
        @NotEmpty
        @Size(min = 1, max = 20)
        @Column(name = "password")
        private String password;

        public void setUserName(String userName) {
            this.userName = userName;
        }

        public String getUserName() {
            return userName;
        }

        public void setPassword(String password) {
            this.password = password;
        }

        public String getPassword() {
            return password;
        }

        public long getId() {
            return Id;
        }

        public void setId(long id) {
            Id = id;
        }

    }

hibernate.cfg.xml

<session-factory>
 <property name="hibernate.connection.driver_class"> com.mysql.jdbc.Driver</property> 
 <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/spring3login</property> 
 <property name="hibernate.connection.username">root</property>
 <property name="connection.password">root</property>
 <property name="connection.pool_size">1</property>
 <property name="hibernate.dialect"> org.hibernate.dialect.HSQLDialect </property>
 <property name="show_sql">true</property>
 <property name="hibernate.hbm2ddl.auto">create</property>

spring.xml

<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
     <property name="prefix"> <value>/WEB-INF/views/</value> </property> 
     <property name="suffix"> <value>.jsp</value> </property>
</bean>
1
  • lets see your spring config. Commented Jun 26, 2013 at 13:50

3 Answers 3

1

I think you forgot to add property in hibernate.cfg.xml

<property name="hibernate.hbm2ddl.auto">update</property>

By this property if the schema is not available it creates one ,other wise it just updates or inserts the value .This property can be added in hibernate.cfg.xml or in your spring.xml file.

Sign up to request clarification or add additional context in comments.

10 Comments

I have already mapped this property : <property name="hbm2ddl.auto">create</property> why should i use "update" instead of "create" ??
When you use create it will create new database by dropping older one each time when you run the program. It is better to use update so if database already exist it just does the CRUD operations.
If you r getting any exception or error please post it so that it is more understandable...
Any help... still same problem.
this is my hib.cfg.xml coding:- <session-factory> <property name="hibernate.connection.driver_class"> com.mysql.jdbc.Driver </property> <property name="hibernate.connection.url"> jdbc:mysql://localhost:3306/spring3login</property> <property name="hibernate.connection.username">root</property> <property name="connection.password">root</property> <property name="connection.pool_size">1</property> <property name="hibernate.dialect"> org.hibernate.dialect.HSQLDialect </property> <property name="show_sql">true</property> <property name="hibernate.hbm2ddl.auto">create</property>
|
0

From my perspective, It might be the reason that you have no privilege to create table, this could be you have no database created ahead. So create the database manually.

Then it could be that you have no privilege to create table,thus grant appropriate privileges to database user will cope this.

Finally, I assume it is because you omitted the hibernate property <propertyname="hibernate.hbm2ddl.auto">update</property>
or your property file can not be read from classpath.

Comments

0

Annotation @Size(min = 1, max = 50) it's for collections, pls fix it.

1 Comment

but this annotation i am using for validation purpose.... does it relate to table entity or creating any problem for table creation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.