aspose file tools*
The moose likes Object Relational Mapping and the fly likes InstantiationException: Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "InstantiationException:" Watch "InstantiationException:" New topic
Author

InstantiationException:

Rohit Kumar
Ranch Hand

Joined: Jul 19, 2007
Posts: 35
hi,

I am getting this error while logging into my application.

I have 2 tables. Facility and Runway. One FACILITY can have many RUNWAY.

Below is Runway.hbm.xml file:

<hibernate-mapping>
<class name="hdpt.Runway" table="RUNWAY" schema="dbo" catalog="Employ">
<id name="runwayId" type="integer">
<column name="RUNWAY_ID" />
<generator class="assigned" /> //CHANGED TO NATIVE
</id>
<many-to-one name="facility" class="hdpt.Facility" fetch="select" cascade="none" >
<column name="FACILITY_ID" not-null="true" />
</many-to-one>

generator class for Runway is "assigned". I need to add a new record to Runway table and it throws "ids cannot be assigned manually".

So i changed the generator class to "native" in Runway table . When i try to login to application itself after changing the generator class,

it is throwing the below error.

javax.faces.FacesException: #{controller.control}: javax.faces.el.EvaluationException: java.lang.ExceptionInInitializerError
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:78)
at javax.faces.component.UICommand.broadcast(UICommand.java:312)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:267)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:381)
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:75)
Truncated. see log file for complete stacktrace
javax.faces.el.EvaluationException: java.lang.ExceptionInInitializerError
at com.sun.faces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:130)
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:72)
at javax.faces.component.UICommand.broadcast(UICommand.java:312)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:267)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:381)
Truncated. see log file for complete stacktrace
java.lang.ExceptionInInitializerError
at gov.gdot.ooit.asm.util.HibernateUtil.<clinit>(HibernateUtil.java:22)
at gov.gdot.ooit.asm.trans.LoginTransaction.begin(LoginTransaction.java:21)
at gov.gdot.ooit.asm.model.Login.logIn(Login.java:43)
at gov.gdot.ooit.asm.command.SignInCommand.execute(SignInCommand.java:28)
at gov.gdot.ooit.asm.control.ASMController.control(ASMController.java:91)
Truncated. see log file for complete stacktrace
org.hibernate.InstantiationException: could not instantiate test objecthdpt..Runway
at org.hibernate.engine.UnsavedValueFactory.instantiate(UnsavedValueFactory.java:25)
at org.hibernate.engine.UnsavedValueFactory.getUnsavedIdentifierValue(UnsavedValueFactory.java:44)
at org.hibernate.tuple.PropertyFactory.buildIdentifierProperty(PropertyFactory.java:44)
at org.hibernate.tuple.EntityMetamodel.<init>(EntityMetamodel.java:114)
at org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:424)
Truncated. see log file for complete stacktrace
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:494)
at org.hibernate.engine.UnsavedValueFactory.instantiate(UnsavedValueFactory.java:22)
Truncated. see log file for complete stacktrace


Any suggestions. why is failing to login to application itself after changing the generator class of Runway.
Shailesh Kini
Ranch Hand

Joined: Oct 17, 2001
Posts: 153
Hi Rohit,

What generator scheme is being used by your database to generate an ID? If you are using oracle database you will have to use sequences. In sqlserver and sybase you will have to make RUNWAY_ID as identity columns. Can you please try the following. Column tag has insert and update attributes. Set insert=false and update=false. Also, change the generator back to assigned.

Hope this works.


Shailesh Kini.
Rohit Kumar
Ranch Hand

Joined: Jul 19, 2007
Posts: 35
Hi Shailesh,

I am using sql server and Runway_Id is the identity column.

when i add column attributes insert=false and update=false to facility column with generator class (Runway table)back to assigned, i was able to login my application.
<hibernate-mapping>
<class name="hdpt.Runway" table="RUNWAY" schema="dbo" catalog="Employ">
<id name="runwayId" type="integer" >
<column name="RUNWAY_ID" />
<generator class="assigned" />
</id>
<many-to-one name="facility" class="hdpt..Facility" fetch="select" cascade="none" insert="false" update = "false"> ///Added column attributes INSERT and UPDATE
<column name="FACILITY_ID" not-null="true" />
</many-to-one>



But when I try to add a new to runway table, it is throwing the following error. Because of the following error, i have changed generator class to "native" which is throwing the error that posted in my first post.

ids for this class must be manually assigned before calling save(): hdpt.Runway
org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before calling save(): hdtp..Runway
at org.hibernate.id.Assigned.generate(Assigned.java:33)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:98)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:186)
at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:33)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:175)
at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:27)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:535)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:523)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:519)
at hdpt.trans.RunwayTrans.addCommonRunway(RunwayTrans.java:962)
at hdpt.model.AddRunway.update(AddRunway.java:50)
at hdpt.command.UpdateCommand.execute(UpdateCommand.java:27)
at gov.gdot.ooit.asm.control.ASMController.control(ASMController.java:93)
at gov.gdot.ooit.asm.control.ASMController.clientIDSelected(ASMController.java:128)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at com.sun.faces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:126)
at javax.faces.component.UIInput.broadcast(UIInput.java:492)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:267)
at javax.faces.component.UIViewRoot.processUpdates(UIViewRoot.java:364)
at com.sun.faces.lifecycle.UpdateModelValuesPhase.execute(UpdateModelValuesPhase.java:81)
at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:200)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:90)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:197)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:225)
at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:127)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:283)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:175)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3214)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:121)
at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:1983)
at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:1890)
at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1344)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:209)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:181)
gov.gdot.ooit.asm.exceptions.ASMException: An exception has occurred when accessing database, Please contact Administrator
at gov.gdot.ooit.asm.trans.RunwayTrans.addCommonRunway(RunwayTrans.java:971)
at gov.gdot.ooit.asm.model.AddRunway.update(AddRunway.java:50)
at gov.gdot.ooit.asm.command.UpdateCommand.execute(UpdateCommand.java:27)
at gov.gdot.ooit.asm.control.ASMController.control(ASMController.java:93)
at gov.gdot.ooit.asm.control.ASMController.clientIDSelected(ASMController.java:128)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at com.sun.faces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:126)
at javax.faces.component.UIInput.broadcast(UIInput.java:492)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:267)
at javax.faces.component.UIViewRoot.processUpdates(UIViewRoot.java:364)
at com.sun.faces.lifecycle.UpdateModelValuesPhase.execute(UpdateModelValuesPhase.java:81)
at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:200)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:90)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:197)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:225)
at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:127)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:283)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:175)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3214)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:121)
at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:1983)
at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:1890)
at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1344)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:209)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:181)
gov.gdot.ooit.asm.exceptions.ASMException
at gov.gdot.ooit.asm.model.AddRunway.update(AddRunway.java:56)
at gov.gdot.ooit.asm.command.UpdateCommand.execute(UpdateCommand.java:27)
at gov.gdot.ooit.asm.control.ASMController.control(ASMController.java:93)
at gov.gdot.ooit.asm.control.ASMController.clientIDSelected(ASMController.java:128)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at com.sun.faces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:126)
at javax.faces.component.UIInput.broadcast(UIInput.java:492)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:267)
at javax.faces.component.UIViewRoot.processUpdates(UIViewRoot.java:364)
at com.sun.faces.lifecycle.UpdateModelValuesPhase.execute(UpdateModelValuesPhase.java:81)
at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:200)

Any suggestions, so that I can add new records to Runway table
Shailesh Kini
Ranch Hand

Joined: Oct 17, 2001
Posts: 153
Hi Rohit,

Please correct me if I am wrong. From your post it seems like you have added the insert=false and update=false to the "<many-to-one>" tag. Instead it should have been allied to the <column name="RUNAWAY_ID" insert=false update=false>. By doing this we are not including RUNAWAY_ID in the insert and update sql statement so the DB engine will assign a new unique value to this column during insert and it will never be updated again.
Rohit Kumar
Ranch Hand

Joined: Jul 19, 2007
Posts: 35
Hi shailesh,

Thanks for the reply. When i add insert and update attributes to Column tag , it is showing error(like dotted red line under Insert and Update..when i put cursor on the top it shows - Attribute "insert" must be declared for element type "column").

<hibernate-mapping>
<class name="hdpt.Runway" table="RUNWAY" schema="dbo" catalog="Aviation">
<id name="runwayId" type="integer" >
<column name="RUNWAY_ID" insert="false" update="false"/>// RED DOTTED LINE SHOWS UNDER insert and update
<generator class="assigned" />
</id>
<many-to-one name="facility" class="hdpt.Facility" fetch="select" cascade="none" >
<column name="FACILITY_ID" not-null="true" />
</many-to-one>
Can you please tell me what am I doing wrong.

-Rohit
Shailesh Kini
Ranch Hand

Joined: Oct 17, 2001
Posts: 153
Hi Rohit,

Sorry I was wrong... not a Hibernate expert. Fortunately for you... hibernate provides a scheme to create an identity value for you. You do not have to use insert=false and update=false any more. Just use the following.

<generator class='identity' />. This should fix your issue.

Also user this link hibernate built in generators to lookup all the available hibernate generators.
Rohit Kumar
Ranch Hand

Joined: Jul 19, 2007
Posts: 35
Hi Shailesh,

I tried with differnet generator classes(Identity, native) , but it is still throwing the same error. It is failing even to login my application.

Any other suggestions...

Thanks for your time on this.
Saathvik Reddy
Ranch Hand

Joined: Jun 03, 2005
Posts: 228
If you are using <generator class="assigned" /> then you have manually assign a value to it.
If you want hibernate to generate the ID you can try using
<generator class="uuid.hex"/>

uuid.hex is an algorithm used by hibenate to generate unique id's
Shailesh Kini
Ranch Hand

Joined: Oct 17, 2001
Posts: 153
Hi Rohit,

It would be helpful if you post the code that's trying to insert a record in RUNWAY table. Also can you post your mapping file for Facility? What is the generator scheme you are using for it? In my opinion <generator class="identity" /> should work in this case. It will help to look at the code just to make sure how the record is being inserted.
Rohit Kumar
Ranch Hand

Joined: Jul 19, 2007
Posts: 35
Hi Shailesh and Reddy,


Thanks for the help and ypur valuable time. I used generator class as Identity and it throwed error and didnt allowed me login to application.

public RunwayTrans() {
session = HibernateUtil.getInstance().getSession();
//session.beginTransaction();
}

I have session.beginTransaction(); in my action class , which is causing the problem. I commented this, changed generator class to identity ...it works fine now. Able to login to application and able to insert records in Runway table.

-Thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: InstantiationException: