java - Hibernate Schema Export in Eclipse -
i trying learn hibernate cameron mckenzie's book 'hibernate made easy' , have followed steps in book still hitting problem. have following source code user class:
package com.examscam.model; import javax.persistence.entity; import javax.persistence.generatedvalue; import javax.persistence.id; 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); } }
i have following hibernate.cfg.xml file:
<?xml version='1.0' encoding='utf-8'?> <!doctype hibernate-configuration public "-//hibernate/hibernate configuration dtd//en" "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factory> <property name="hibernate.connection.url">jdbc:mysql://localhost/examscam</property> <property name="hibernate.connection.username">root</property> <property name="hibernate.connection.password">password</property> <property name="hibernate.connection.driver_class">com.mysql.jdbc.driver</property> <property name="hibernate.dialect">org.hibernate.dialect.mysqldialect</property> <property name="hibernate.transaction.factory_class">org.hibernate.transaction.jdbctransactionfactory</property> <property name="hibernate.current_session_context_class">thread</property> <property name="hibernate.show_sql">true</property> </session-factory> </hibernate-configuration>
i have following persistence.xml file:
<?xml version="1.0" encoding="utf-8"?> <persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"> <persistence-unit name="welcome1"> <class>com.examscam.model.user</class> </persistence-unit> </persistence>
i using mysql, , mysql server instance running.
i not experiencing compilation errors or problems imports.
i have reread instructions in book , cannot see may have inadvertently missed, eg have jdbc drivers , necessary jars.
when attempt run class though, eclipse returns error message
0 [main] error org.hibernate.tool.hbm2ddl.schemaexport - schema export unsuccessful java.lang.nullpointerexception @ org.hibernate.util.confighelper.getresourceasstream(confighelper.java:144) @ org.hibernate.tool.hbm2ddl.schemaexport.execute(schemaexport.java:166) @ org.hibernate.tool.hbm2ddl.schemaexport.create(schemaexport.java:133) @ com.examscam.model.user.main(user.java:35)
[sometimes, returns 1 instead of 0 can't see obvious pattern it.]
can suggest can make work? it's extremely frustrating as, obviously, cannot @ if can't run.
thanks, conor
Comments
Post a Comment