java - Initial SessionFactory creation failed.org.hibernate.HibernateException: Missing column -


expected result: how print data college role shared screen shot link

screen shot: http://imgur.com/h3wolab project structure: http://imgur.com/irxgjeq

working on simple login , show user type data created hibernate project in eclipse juno using 2 classes 1) college_userlogin 2) college_role

and trying data 2nd class usertype (say student) using common key 'roleid' mentioned in both classes. getting exception , stuck,

stacktrace

initial sessionfactory creation failed.org.hibernate.hibernateexception: missing column: college_userlogin in cerpdevnew.dbo.college_role

note: college_userlogin table not column compiler understanding column problem

    @entity      @table(name = "college_role")      //@inheritance(strategy = javax.persistence.inheritancetype.table_per_class)      //@discriminatorvalue("college_role")      //@primarykeyjoincolumn(name="roleid")      public class college_role implements serializable {          private static final long serialversionuid = 9182318500460817975l;          @id          //@generatedvalue(strategy=generationtype.auto)          //@onetoone(mappedby="collegerole")          //@primarykeyjoincolumn(name="roleid")          //@joincolumn(name="roleid",referencedcolumnname="roleid", unique= true, nullable=true, updatable = false, insertable = false)          @joincolumn(name="roleid",unique= true, nullable=false, insertable=false, updatable=false)          public college_userlogin college_userlogin;           public college_userlogin getcollege_userlogin() {                return college_userlogin;              }              public void setcollege_userlogin(college_userlogin college_userlogin) {                this.college_userlogin = college_userlogin;              }            @column(name="roleid")         private int roleid;      ://body      **college_userlogin.java**       @entity      @table(name = "college_userlogin")      //@inheritance(strategy = inheritancetype.single_table)      //@discriminatorcolumn(name = "college_userlogin", discriminatortype = discriminatortype.string)      public class college_userlogin implements serializable {           private static final long serialversionuid = 6304741905092879739l;          @id          //@generatedvalue(strategy=generationtype.identity)          //@attributeoverride(name="roleid", column=@column(name="roleid"))          // @onetoone(cascade=cascadetype.all, mappedby="college_userlogin")      //  @primarykeyjoincolumn          //@joincolumn(name="roleid",referencedcolumnname="role_id", unique= true, nullable=true, updatable = false, insertable = false)           private college_role college_role;          public college_role getcollege_role() {              return college_role;            }           public void setcollege_role(college_role college_role) {              this.college_role = college_role;            }           public college_userlogin(){          }     //body 

updated hibernateutil class

public class hibernateutil { private static final sessionfactory sessionfactory = buildsessionfactory(); private static serviceregistry serviceregistry; private static configuration configuration;  **added entity manager factory , entity manager**  static entitymanagerfactory emf = persistence.createentitymanagerfactory("rest-ws"); static entitymanager em = emf.createentitymanager();   /*  sql, dml entities must registered */ public static void registerbeans() {     configuration.addannotatedclass(college_userlogin.class);     configuration.addannotatedclass(college_role.class); }      private static final sessionfactory buildsessionfactory() {         try {             configuration = new configuration();             configuration.configure();             registerbeans();          serviceregistry = new serviceregistrybuilder().applysettings(configuration.getproperties()).buildserviceregistry();          return configuration.buildsessionfactory(serviceregistry);     }     catch (throwable ex) {         // make sure log exception, might swallowed         system.err.println("initial sessionfactory creation failed." + ex);         throw new exceptionininitializererror(ex);      } }      public static void main(string args[]) throws exception {     //these line have added//     em.gettransaction().begin();         college_userlogin college_userlogin = new college_userlogin();               em.persist(college_userlogin);         college_role college_role = new college_role();     //  college_role.setname("dept name");       college_userlogin.setcollege_role(college_role);         em.flush();             //up here these lines have added//       hibernateutil.getsessionfactory();      //changes made      configuration cfg=new configuration();           cfg.configure("hibernate.cfg.xml");            session session=sessionfactory.opensession();        //   query query=session.createquery("select * college_userlogin userid='atme.admin'");           @suppresswarnings("unchecked")         list<college_userlogin> list= (list<college_userlogin> )session.createquery("from college_userlogin userid='atme.admin' ").list();           iterator<college_userlogin> itr=list.iterator();          // while(itr.hasnext()){               //college_userlogin clg_login = null;         college_userlogin clg_login=itr.next();            system.out.println(clg_login.getuserid() + itr.next() +" "+ clg_login.getemailid() + itr.next());            college_role clg_role =clg_login.getcollege_role();  ;          system.out.println(" "+                    clg_role.getroledescription() + itr.next() +" "+clg_role.getsuperiorheirarchy() + itr.next());     //these lines have added//       system.out.println("success");      em.gettransaction().commit();     em.close();     emf.close();  }      } 

complete stack trace

sep 30, 2015 12:28:03 pm org.hibernate.annotations.common.version <clinit>  info: hcann000001: hibernate commons annotations {4.0.1.final}  sep 30, 2015 12:28:03 pm org.hibernate.version logversion  info: hhh000412: hibernate core {4.0.0.final}  sep 30, 2015 12:28:03 pm org.hibernate.cfg.environment <clinit>  info: hhh000206: hibernate.properties not found  sep 30, 2015 12:28:03 pm org.hibernate.cfg.environment buildbytecodeprovider  info: hhh000021: bytecode provider name : javassist  sep 30, 2015 12:28:03 pm org.hibernate.cfg.configuration configure  info: hhh000043: configuring resource: /hibernate.cfg.xml  sep 30, 2015 12:28:03 pm org.hibernate.cfg.configuration  getconfigurationinputstream  info: hhh000040: configuration resource: /hibernate.cfg.xml  sep 30, 2015 12:28:04 pm org.hibernate.cfg.configuration doconfigure  info: hhh000041: configured sessionfactory: null  sep 30, 2015 12:28:04 pm   org.hibernate.service.jdbc.connections.internal.drivermanagerconnectionprovideri mpl configure  info: hhh000402: using hibernate built-in connection pool (not production use!)  sep 30, 2015 12:28:04 pm org.hibernate.service.jdbc.connections.internal.drivermanagerconnectionproviderimpl configure  info: hhh000115: hibernate connection pool size: 100  sep 30, 2015 12:28:04 pm org.hibernate.service.jdbc.connections.internal.drivermanagerconnectionproviderimpl configure  info: hhh000006: autocommit mode: true  sep 30, 2015 12:28:04 pm org.hibernate.service.jdbc.connections.internal.drivermanagerconnectionproviderimpl configure  info: hhh000401: using driver [com.microsoft.sqlserver.jdbc.sqlserverdriver] @   url [jdbc:sqlserver://172.18.1.30;database=cerpdevnew;] sep 30, 2015 12:28:04 pm org.hibernate.service.jdbc.connections.internal.drivermanagerconnectionproviderimpl configure  info: hhh000046: connection properties: {user=sa, password=****, autocommit=true}  sep 30, 2015 12:28:04 pm org.hibernate.dialect.dialect <init>  info: hhh000400: using dialect: org.hibernate.dialect.sqlserver2008dialect sep 30, 2015 12:28:04 pm  org.hibernate.engine.transaction.internal.transactionfactoryinitiator initiateservice  info: hhh000268: transaction strategy: org.hibernate.engine.transaction.internal.jdbc.jdbctransactionfactory  sep 30, 2015 12:28:04 pm   org.hibernate.hql.internal.ast.astquerytranslatorfactory <init>  info: hhh000397: using astquerytranslatorfactory  sep 30, 2015 12:28:04 pm org.hibernate.validator.internal.util.version <clinit>  info: hv000001: hibernate validator 5.1.2.final  sep 30, 2015 12:28:04 pm org.hibernate.tool.hbm2ddl.schemavalidator validate  info: hhh000229: running schema validator  sep 30, 2015 12:28:04 pm org.hibernate.tool.hbm2ddl.schemavalidator validate  info: hhh000102: fetching database metadata  sep 30, 2015 12:28:04 pm org.hibernate.tool.hbm2ddl.tablemetadata <init>  info: hhh000261: table found: cerpdevnew.dbo.college_role  sep 30, 2015 12:28:04 pm org.hibernate.tool.hbm2ddl.tablemetadata <init>  info: hhh000037: columns: [stafftype, isactive, superiorheirarchy, roleid, roledescription]  initial sessionfactory creation failed.org.hibernate.hibernateexception: missing column: college_userlogin in cerpdevnew.dbo.college_role  exception in thread "main" java.lang.exceptionininitializererror      @ com.orcta.dao.hibernateutil.buildsessionfactory(hibernateutil.java:40)      @ com.orcta.dao.hibernateutil.<clinit>(hibernateutil.java:17)  caused by: org.hibernate.hibernateexception: missing column: college_userlogin in cerpdevnew.dbo.college_role      @ org.hibernate.mapping.table.validatecolumns(table.java:275)      @ org.hibernate.cfg.configuration.validateschema(configuration.java:1268)      @   org.hibernate.tool.hbm2ddl.schemavalidator.validate(schemavalidator.java:155)      @ org.hibernate.internal.sessionfactoryimpl.<init>(sessionfactoryimpl.java:453)      @ org.hibernate.cfg.configuration.buildsessionfactory(configuration.java:1737)      @ com.orcta.dao.hibernateutil.buildsessionfactory(hibernateutil.java:35)      ... 1 more 

thanks in advance. great beginner in advanced java

@piyushsoni must not comment @onetoone , @joincolumn annotations! cause of hibernate thinks column (it must association foreign key). must add @onetoone , @joincolumn annotations in college_userlogin class, , add @onetoone "mappedby" in college_role class. annotations have foreign key field in college_userlogin linked college_role.

if want have foreign keys in college_userlogin , college_role must add @onetoone , @joincolumn annotations in college_userlogin class, , add @onetoone , @joincolumn annotations in college_role class.

i have prepared example you. uses user class (analogue of college_userlogin) , useraddress class (analogue of college_role calss). please, see annotations on methods user.getaddress() , useraddress.getuser().


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -