0

I have a little problem, When I insert a new value, the program does not work and it will not recreate the table in sql,Please check the code an let me know if there is any mistake, I am using Hibernate 5

1) Main class

    package yashwanth;
    import org.hibernate.Session;
    import org.hibernate.SessionFactory;
    import org.hibernate.cfg.Configuration;

    public class HibernateTest {

     public static void main(String[] args) {
        // TODO Auto-generated method stub
     UserDetails user=new UserDetails();
    user.setUserId(2);
user.setUserName("Second User");
SessionFactory SessionFactory=new     Configuration().configure().buildSessionFactory();
Session session=SessionFactory.openSession();
    session.beginTransaction();
    session.save(user);
    session.getTransaction().commit();
    }
}

2)

package yashwanth;
import javax.persistence.Entity;
import javax.persistence.Id;
@Entity
public class UserDetails {
@Id
    private int userId;
    private String userName;
    public int getUserId() {
        return userId;
    }
    public void setUserId(int userId) {
        this.userId = userId;
    }
    public String getUserName() {
        return userName;
    }
    public void setUserName(String userName) {
        this.userName = userName;
    }
}

Error log

Console:
Jul 04, 2015 1:46:00 AM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {5.0.0.CR1}
Jul 04, 2015 1:46:00 AM org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
Jul 04, 2015 1:46:00 AM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
Jul 04, 2015 1:46:01 AM org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {4.0.5.Final}
Jul 04, 2015 1:46:01 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
WARN: HHH000402: Using Hibernate built-in connection pool (not for production use!)
Jul 04, 2015 1:46:01 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH000401: using driver [com.mysql.jdbc.Driver] at URL [jdbc:mysql://localhost/firstjdbcdata]
Jul 04, 2015 1:46:01 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH000046: Connection properties: {user=root, password=****}
Jul 04, 2015 1:46:01 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH000006: Autocommit mode: false
Jul 04, 2015 1:46:01 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000115: Hibernate connection pool size: 1 (min=1)
Jul 04, 2015 1:46:02 AM org.hibernate.dialect.Dialect <init>
INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQLDialect
Jul 04, 2015 1:46:03 AM org.hibernate.search.engine.Version <clinit>
INFO: HSEARCH000034: Hibernate Search 5.4.0.Alpha1
Jul 04, 2015 1:46:03 AM org.hibernate.tool.hbm2ddl.SchemaExport execute
INFO: HHH000227: Running hbm2ddl schema export
Hibernate: drop table if exists UserDetails
Hibernate: create table UserDetails (userId integer not null, userName varchar(255), primary key (userId))
Jul 04, 2015 1:46:04 AM org.hibernate.tool.hbm2ddl.SchemaExport execute
INFO: HHH000230: Schema export complete
Jul 04, 2015 1:46:04 AM org.hibernate.search.engine.impl.ConfigContext getLuceneMatchVersion
WARN: HSEARCH000075: Configuration setting hibernate.search.lucene_version was not specified: using LUCENE_CURRENT.
Hibernate: insert into UserDetails (userName, userId) values (?, ?)
Bacteria
  • 8,406
  • 10
  • 50
  • 67
potu yashwanth
  • 21
  • 1
  • 10
  • The log you posted shows that Hibernate does recreate the table, and does insert the entity in the database: `drop table if exists UserDetails`; `create table UserDetails (...`; `insert into UserDetails ...`. So, what's the actual problem? – JB Nizet Jul 04 '15 at 05:55
  • In the program First I gave user.setUserID(1) and user.set Name(first user) and then I chaged to user.setUserID(2) and user.setName(second user) but the values in the table doesnot change it remained 1 and first user, I think it should be changing to 2.second user Thanks For the response Nizet – potu yashwanth Jul 04 '15 at 06:05
  • http://stackoverflow.com/users/571407/jb-nizet If u can find y it's happening it will be very useful – potu yashwanth Jul 04 '15 at 18:45

0 Answers0