java - Strange NumberFormatException in Hibernate When Using SessionFactory -


[it may useful see related, yet distinct, question earlier today here hibernate schema export in eclipse .]

i have following java class

package com.examscam.model; import javax.persistence.entity; import javax.persistence.generatedvalue; import javax.persistence.id; import org.hibernate.session; import org.hibernate.sessionfactory; import org.hibernate.cfg.annotationconfiguration; import org.hibernate.tool.hbm2ddl.schemaexport;  @entity public class user {     private long id;     private string password;      @id     @generatedvalue     public long getid() {         return id;     }      public string getpassword() {         return password;     }      public void setid(long id) {         this.id = id;     }      public void setpassword(string password) {         this.password = password;     }      public static void main(string[] args) {         annotationconfiguration config = new annotationconfiguration();         config.addannotatedclass(user.class);         config.configure(); //      new schemaexport(config).create(true, true);          sessionfactory factory = config.buildsessionfactory();         session session = factory.getcurrentsession();         session.begintransaction();          user u = new user();                 u.setpassword("abc123");          session.saveorupdate(u);         session.gettransaction().commit();          system.out.println("done.");     } } 

i have (mysql) database , have created user table code

create table user (id integer not null auto_increment, password varchar(255), primary key (id)) 

however, when try running code, given following stack trace

exception in thread "main" java.lang.numberformatexception: input string: ""     @ java.lang.numberformatexception.forinputstring(numberformatexception.java:48)     @ java.lang.integer.parseint(integer.java:470)     @ java.lang.integer.valueof(integer.java:554)     @ org.hibernate.util.propertieshelper.getinteger(propertieshelper.java:37)     @ org.hibernate.connection.drivermanagerconnectionprovider.configure(drivermanagerconnectionprovider.java:47)     @ org.hibernate.connection.connectionproviderfactory.newconnectionprovider(connectionproviderfactory.java:124)     @ org.hibernate.connection.connectionproviderfactory.newconnectionprovider(connectionproviderfactory.java:56)     @ org.hibernate.cfg.settingsfactory.createconnectionprovider(settingsfactory.java:414)     @ org.hibernate.cfg.settingsfactory.buildsettings(settingsfactory.java:62)     @ org.hibernate.cfg.configuration.buildsettings(configuration.java:2009)     @ org.hibernate.cfg.configuration.buildsessionfactory(configuration.java:1292)     @ org.hibernate.cfg.annotationconfiguration.buildsessionfactory(annotationconfiguration.java:859)     @ com.examscam.model.user.main(user.java:40) 

line 40 of user class is

    sessionfactory factory = config.buildsessionfactory(); 

does have idea why happening? not entering empty string anywhere on line , have copied code book. have no doubt book correct; questions more along lines of 'can think of reason (errors in xml files, classpath ordering issues, files not being in correct directories etc) why behaviour occur?'.

an answer question might solve issue in link @ top of page exporting schema.

thanks, conor.

so believe i've solved problem ended being 2 problems. first, there older copy of hibernate in classpath. older version requiring config elements no longer required, leading numberformatexception trying parse empty string int missing transaction isolation config element.

after fixing that, started see nullpointerexception on line of code:

environment.class.getclassloader().getresourceasstream(stripped); 

looking @ line of code, thing have been throwing npe getclassloader call, how ever null? turns out getclassloader can return null if class loader being returned boot class loader. asked conor check if had put hibernate boot class path , turns out did. removing boot class fixed issue.

so 2 lessons here:

  1. manage class path carefully. know what's on , keep trim possible. less 3rd party libs better.
  2. don't ever put stuff on boot class path. if decide ignore rule, understand potential implications you're not stuck chasing issues this.

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -