org.hibernate.MappingException: Could not determine type for: java.util.List, at table: College, for columns: [org.hibernate.mapping.Column(students)] -
now, learning hibernate, , started using in project. crud application. used hibernate crud operations. works of them. but, one-to-many & many-to-one, tired of trying it. gives me below error.
org.hibernate.mappingexception: not determine type for: java.util.list, @ table: college, columns: [org.hibernate.mapping.column(students)]
then again went through video tutorial. simple me, in beginning. but, cant make work. now, says
org.hibernate.mappingexception: not determine type for: java.util.list, @ table: college, columns: [org.hibernate.mapping.column(students)]
i have ran searches in internet, there telling its bug in hibernate, , says, adding @genereatedvalue error ll cleared. but, nothings works me,
i hope ll fix!!
thanks!
here code:
college.java
@entity public class college { @id @generatedvalue(strategy=generationtype.auto) private int collegeid; private string collegename; private list<student> students; @onetomany(targetentity=student.class, mappedby="college", fetch=fetchtype.eager) public list<student> getstudents() { return students; } public void setstudents(list<student> students) { this.students = students; }//other gettters & setters omitted
student.java
@entity public class student { @id @generatedvalue(strategy=generationtype.auto) private int studentid; private string studentname; private college college; @manytoone @joincolumn(name="collegeid") public college getcollege() { return college; } public void setcollege(college college) { this.college = college; }//other gettters & setters omitted
main.java:
public class main { private static org.hibernate.sessionfactory sessionfactory; public static sessionfactory getsessionfactory() { if (sessionfactory == null) { initsessionfactory(); } return sessionfactory; } private static synchronized void initsessionfactory() { sessionfactory = new annotationconfiguration().configure().buildsessionfactory(); } public static session getsession() { return getsessionfactory().opensession(); } public static void main (string[] args) { session session = getsession(); transaction transaction = session.begintransaction(); college college = new college(); college.setcollegename("dr.mcet"); student student1 = new student(); student1.setstudentname("peter"); student student2 = new student(); student2.setstudentname("john"); student1.setcollege(college); student2.setcollege(college); session.save(student1); session.save(student2); transaction.commit(); } }
console:
exception in thread "main" org.hibernate.mappingexception: not determine type for: java.util.list, @ table: college, columns: [org.hibernate.mapping.column(students)] @ org.hibernate.mapping.simplevalue.gettype(simplevalue.java:306) @ org.hibernate.mapping.simplevalue.isvalid(simplevalue.java:290) @ org.hibernate.mapping.property.isvalid(property.java:217) @ org.hibernate.mapping.persistentclass.validate(persistentclass.java:463) @ org.hibernate.mapping.rootclass.validate(rootclass.java:235) @ org.hibernate.cfg.configuration.validate(configuration.java:1330) @ org.hibernate.cfg.configuration.buildsessionfactory(configuration.java:1833) @ test.hibernate.main.initsessionfactory(main.java:22) @ test.hibernate.main.getsessionfactory(main.java:16) @ test.hibernate.main.getsession(main.java:27) @ test.hibernate.main.main(main.java:43)
the xml:
<?xml version='1.0' encoding='utf-8'?> <!doctype hibernate-configuration public "-//hibernate/hibernate configuration dtd 3.0//en" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factory> <!-- database connection settings --> <property name="connection.driver_class">com.mysql.jdbc.driver</property> <property name="connection.url">jdbc:mysql://localhost:3306/dummy</property> <property name="connection.username">root</property> <property name="connection.password">1234</property> <!-- jdbc connection pool (use built-in) --> <property name="connection.pool_size">1</property> <!-- sql dialect --> <property name="dialect">org.hibernate.dialect.mysqldialect</property> <!-- enable hibernate's automatic session context management --> <property name="current_session_context_class">thread</property> <!-- disable second-level cache --> <property name="cache.provider_class">org.hibernate.cache.nocacheprovider</property> <!-- echo executed sql stdout --> <property name="show_sql">true</property> <!-- drop , re-create database schema on startup --> <property name="hbm2ddl.auto">update</property> <mapping class="test.hibernate.student" /> <mapping class="test.hibernate.college" /> </session-factory>
you using field access strategy (determined @id annotation). put jpa related annotation right above each field instead of getter property
@onetomany(targetentity=student.class, mappedby="college", fetch=fetchtype.eager) private list<student> students;
Comments
Post a Comment