permaculture playing cards*
The moose likes Object Relational Mapping and the fly likes Not able to get a Session Factory Object Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Not able to get a Session Factory Object" Watch "Not able to get a Session Factory Object" New topic
Author

Not able to get a Session Factory Object

Kamal Bindra
Greenhorn

Joined: May 18, 2012
Posts: 8
Hi,

I am trying to join two tables User and Album_Detail where Album_Detail has a foreign key userid and id is PK in User. this ia what i have wrriten in code
@OneToMany(cascade = CascadeType.ALL)
@JoinTable(name = "USER_ALBUMS", joinColumns = { @JoinColumn(table = "USER", name = "ID") }, inverseJoinColumns = { @JoinColumn(table = "ALBUM_DETAIL", name = "ID") })

But i ma getting this exception...please help me to fix the issue.
Any help is highly appreciated in advance and here are the logs..


org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.hibernate.AnnotationException: Cannot find the expected secondary tabl advancee: no USER available for com.nstudio.itoddler.common.TimeLogPojo
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:656)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:549)
javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)

root cause

org.hibernate.AnnotationException: Cannot find the expected secondary table: no USER available for com.nstudio.itoddler.common.TimeLogPojo
org.hibernate.cfg.Ejb3Column.getJoin(Ejb3Column.java:293)
org.hibernate.cfg.Ejb3Column.getTable(Ejb3Column.java:272)
org.hibernate.cfg.AnnotationBinder.bindManyToOne(AnnotationBinder.java:1946)
org.hibernate.cfg.AnnotationBinder.bindOneToOne(AnnotationBinder.java:2116)
org.hibernate.cfg.AnnotationBinder.processElementAnnotations(AnnotationBinder.java:1403)
org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:754)
org.hibernate.cfg.AnnotationConfiguration.processArtifactsOfType(AnnotationConfiguration.java:534)
org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:286)
org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1292)
org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:859)
com.nstudio.itoddler.util.HibernateUtil.getSessionFactory(HibernateUtil.java:13)
com.nstudio.itoddler.service.impl.UserBusinessService.addUser(UserBusinessService.java:21)
com.nstudio.itoddler.ws.action.UserServlet.addUser(UserServlet.java:31)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:597)
org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:176)
org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:426)
org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:414)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:790)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:549)
javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)


Thanks,
Kamal Bindra
Bill Gorder
Bartender

Joined: Mar 07, 2010
Posts: 1672
    
    7

OK well this is not a Spring issue it is an ORM issue. You would probably get better attention posting this question in the ORM forum..

That said you have not posted enough information to really help you, but I am not sure you need a join table for this. You have a One to many so on the inverse side you will have a many to one. Since I have no idea the context of the application I will give you a different example. Consider an Employee and a Department, where a department has many employees but an employee can only belong to one department. Note the generation strategy was chosen for simplicity it is not usually the best choice.





The ddl for something like this could be like below (shown for Derby)


[How To Ask Questions][Read before you PM me]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Not able to get a Session Factory Object