java - hibernate table creating in database -
my alien.java file here
package com.hibernate; import javax.persistence.entity; import javax.persistence.id; @entity public class alien { @id private int aid; private string aname; private string colour; public int getaid() { return aid; } public void setaid(int aid) { this.aid = aid; } public string getaname() { return aname; } public void setaname(string aname) { this.aname = aname; } public string getcolour() { return colour; } public void setcolour(string colour) { this.colour = colour; } }
app.java file here
package com.hibernate; import org.hibernate.session; import org.hibernate.sessionfactory; import org.hibernate.transaction; import org.hibernate.cfg.configuration; public class app { public static void main(string[] args) { alien dasaradh = new alien(); dasaradh.setaid(141); dasaradh.setaname("bobby"); dasaradh.setcolour("black"); configuration con = new configuration().configure().addannotatedclass(alien.class); sessionfactory sessionfactory = new configuration().configure().buildsessionfactory(); session session = sessionfactory.opensession(); transaction tx = session.begintransaction(); session.save(dasaradh); tx.commit(); } }
the probem it's not connecting database.
looks hibernate.cfg.xml has wrong format.
try change header be
<?xml version='1.0' encoding='utf-8'?> <!doctype hibernate-configuration public "-//hibernate/hibernate configuration dtd//en" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> <hibernate-configuration> ...
or try correct xml tutorial , replace content yours.
Comments
Post a Comment