Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Object Relational Mapping
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Tim Cooke
Campbell Ritchie
paul wheaton
Ron McLeod
Devaka Cooray
Sheriffs:
Jeanne Boyarsky
Liutauras Vilda
Paul Clapham
Saloon Keepers:
Tim Holloway
Carey Brown
Piet Souris
Bartenders:
Forum:
Object Relational Mapping
Annotations exception
Swaroop Kunduru
Ranch Hand
Posts: 40
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Class: User_Details.java
package com.hibernate.domain; import java.util.HashSet; import java.util.Set; import javax.persistence.Column; import javax.persistence.ElementCollection; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.SequenceGenerator; import javax.persistence.Table; @Entity @Table (name="USER_DETAILS") @SequenceGenerator(name="UsrDtls_seq", sequenceName="UsrDtls_seq", initialValue=1, allocationSize=1) public class User_Details { private int userID; private String fName; private String lName; @ElementCollection private Set<Address> adresses = new HashSet<Address>(); @Id @GeneratedValue (strategy=GenerationType.AUTO) public int getUserID() { return userID; } public void setUserID(int userID) { this.userID = userID; } @Column(name="FirstName" , length=25) public String getfName() { return fName; } public void setfName(String fName) { this.fName = fName; } @Column(name="LastName" , length=25) public String getlName() { return lName; } public void setlName(String lName) { this.lName = lName; } public Set<Address> getAdresses() { return adresses; } public void setAdresses(Set<Address> adresses) { this.adresses = adresses; } }
Class: Address.java
package com.hibernate.domain; import javax.persistence.Column; import javax.persistence.Embeddable; @Embeddable public class Address { @Column(name="Address_Line" , length=100) private String addrLineOne; @Column(name="City" , length=40) private String city; @Column(name="State" , length=2) private String state; @Column(name="Zip" , length=5) private String zip; public String getAddrLineOne() { return addrLineOne; } public void setAddrLineOne(String addrLineOne) { this.addrLineOne = addrLineOne; } public String getCity() { return city; } public void setCity(String city) { this.city = city; } public String getState() { return state; } public void setState(String state) { this.state = state; } public String getZip() { return zip; } public void setZip(String zip) { this.zip = zip; } }
Class : HibernateUtil.java
package com.hibernate.util; import org.hibernate.SessionFactory; import org.hibernate.cfg.Configuration; public class HibernateUtil { private static final SessionFactory sessionFactory = buildSessionFactory(); private static SessionFactory buildSessionFactory() { try { // Create the SessionFactory from hibernate.cfg.xml return new Configuration().configure().buildSessionFactory(); } catch (Throwable ex) { // Make sure you log the exception, as it might be swallowed System.err.println("Initial SessionFactory creation failed." + ex); throw new ExceptionInInitializerError(ex); } } public static SessionFactory getSessionFactory() { return sessionFactory; } public static void shutdown() { // Close caches and connection pools getSessionFactory().close(); } }
Class: Test.java
package com.hibernate.test; import org.hibernate.Session; import com.hibernate.domain.Address; import com.hibernate.domain.User_Details; import com.hibernate.util.HibernateUtil; public class Test { /** * @param args */ public static void main(String[] args) { Session session = HibernateUtil.getSessionFactory().openSession(); User_Details user = new User_Details(); Address address = new Address(); address.setAddrLineOne("100 Liones Ln"); address.setCity("Lewisville"); address.setState("TX"); address.setZip("75056"); Address address2 = new Address(); address2.setAddrLineOne("3801 W Spring Creek pkwy #713"); address2.setCity("Plano"); address2.setState("TX"); address2.setZip("75023"); user.setfName("Swaroop"); user.setlName("Kunduru"); user.getAdresses().add(address); user.getAdresses().add(address2); session.beginTransaction(); session.save(user); session.getTransaction().commit(); session.close(); user = null; address = null; } }
Config: hibernate.cfg.xml
<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factory> <property name="hibernate.connection.driver_class">org.postgresql.Driver</property> <property name="hibernate.connection.url">jdbc:postgresql://localhost:5432/HibernateLearn</property> <property name="hibernate.max_fetch_depth">3</property> <property name="hibernate.connection.username">postgres</property> <property name="hibernate.connection.password">warangal</property> <property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property> <property name="show_sql">true</property> <property name="format_sql">true</property> <property name="hbm2ddl.auto">create</property> <mapping class="com.hibernate.domain.User_Details" /> </session-factory> </hibernate-configuration>
Error I am getting:
log4j:WARN No appenders could be found for logger (org.jboss.logging). log4j:WARN Please initialize the log4j system properly. log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info. Initial SessionFactory creation failed.org.hibernate.MappingException: Could not determine type for: java.util.Set, at table: USER_DETAILS, for columns: [org.hibernate.mapping.Column(adresses)] Exception in thread "main" java.lang.ExceptionInInitializerError at com.hibernate.util.HibernateUtil.buildSessionFactory(HibernateUtil.java:17) at com.hibernate.util.HibernateUtil.<clinit>(HibernateUtil.java:8) at com.hibernate.test.Test.main(Test.java:16) Caused by: org.hibernate.MappingException: Could not determine type for: java.util.Set, at table: USER_DETAILS, for columns: [org.hibernate.mapping.Column(adresses)] at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:304) at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:288) at org.hibernate.mapping.Property.isValid(Property.java:216) at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:467) at org.hibernate.mapping.RootClass.validate(RootClass.java:268) at org.hibernate.cfg.Configuration.validate(Configuration.java:1287) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1729) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1775) at com.hibernate.util.HibernateUtil.buildSessionFactory(HibernateUtil.java:13) ... 2 more
Regards,
Swaroop Kunduru
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Hibernate Issue
Could not read mappings from resource ?
javabean problem
bidirectional one to many mapping issues
javabean problem
More...