-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 
Author Message
 Post subject: need help in HOW TO UPLOAD data using hibernate
PostPosted: Fri Jan 25, 2008 9:39 am 
Newbie

Joined: Fri Jan 25, 2008 8:32 am
Posts: 15
i am trying to insert the value in databases but it is fired by hibernate...

Hibernate: select unwanted0_.ID as ID0_0_, unwanted0_.name as name0_0_ from UNWANTED unwanted0_ where unwanted0_.ID=?
org.hibernate.MappingException: Unknown entity: java.lang.Long
at org.hibernate.impl.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:548)
at org.hibernate.impl.SessionImpl.getEntityPersister(SessionImpl.java:1338)
at org.hibernate.engine.ForeignKeys.isTransient(ForeignKeys.java:180)
at org.hibernate.event.def.AbstractSaveEventListener.getEntityState(AbstractSaveEventListener.java:487)
at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:70)
at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:38)
at org.hibernate.impl.SessionImpl.firePersist(SessionImpl.java:618)
at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:592)
at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:596)
at org.apache.jsp.unwanted_jsp._jspService(unwanted_jsp.java:131)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:332)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:874)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
at java.lang.Thread.run(Unknown Source)

org.apache.jasper.JasperException: Exception in JSP: /unwanted.jsp:4

1: <%@ include file="protected.jsp" %>
2: <%@ include file="header.jsp" %>
3: <%
4: Long id=Long.valueOf(request.getParameter("Id"));
5: Session sess = HibernateUtil.currentSession();
6: Unwanted u= new Unwanted();
7:


Stacktrace:
my mapping looks like it..
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
<class name="com.ats.custFlight.pojo.Unwanted" table="unwanted" lazy="false">
<id column="ID" name="id" type="java.lang.Long"/>
<property column="name" name="name" type="java.lang.String"/>
</class>
</hibernate-mapping>



my code to upload data is--

Long id=Long.valueOf(request.getParameter("Id"));
Session sess = HibernateUtil.currentSession();
Unwanted u= new Unwanted();

Unwanted u2 = (Unwanted) sess.get (Unwanted.class,(long)77);
u.setId(id);
u.setName("RAHUL");
try{
sess.save(u);
}catch( Exception e )
{
e.printStackTrace();
}
System.out.println(" size is " + u.getId());

my hibernate.util code is--
package com.ats.custFlight.util;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import org.hibernate.*;
import org.hibernate.cfg.*;

public class HibernateUtil {

private static Log log = LogFactory.getLog(HibernateUtil.class);

private static final SessionFactory sessionFactory;

static {
try {
// Create the SessionFactory
sessionFactory = new Configuration().configure().buildSessionFactory();

} catch (Throwable ex) {
// Make sure you log the exception, as it might be swallowed
log.error("Initial SessionFactory creation failed.", ex);
ex.printStackTrace();
throw new ExceptionInInitializerError(ex);
}
}

public static final ThreadLocal < Session > session = new ThreadLocal < Session > ();

public static Session currentSession() throws HibernateException {
Session s = (Session) session.get();
// Open a new Session, if this Thread has none yet
if (s == null) {
s = sessionFactory.openSession();
session.set(s);
}
return s;
}

public static void closeSession() throws HibernateException {
Session s = (Session) session.get();
session.set(null);
if (s != null)
s.close();
}
}
and JAVA CLASS IS..

package com.ats.custFlight.pojo;

public class Unwanted {

Long id;
String name;

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}
}


Last edited by rhlpnt on Mon Jan 28, 2008 1:41 am, edited 2 times in total.

Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 25, 2008 4:42 pm 
Regular
Regular

Joined: Wed Aug 15, 2007 7:37 am
Posts: 73
Looks like your request object doesn't have a parameter called 'Id' from the error. You might want to post this on a Java forum or something; this forum's primarily for .Net NHibernate development.

Steve


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 28, 2008 12:29 am 
Newbie

Joined: Fri Jan 25, 2008 8:32 am
Posts: 15
plz read my problem again


Last edited by rhlpnt on Mon Jan 28, 2008 1:39 am, edited 2 times in total.

Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 28, 2008 1:26 am 
Newbie

Joined: Fri Jan 25, 2008 8:32 am
Posts: 15
ok...but it is mapping problem... I did hibernate mapping like this..The error shows problem in java.lang.Long

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
<class name="com.ats.custFlight.pojo.Unwanted" table="unwanted" lazy="false">
<id column="ID" name="id" type="java.lang.Long"/>
<property column="name" name="name" type="java.lang.String"/>
</class>
</hibernate-mapping>

SteveMc wrote:
Looks like your request object doesn't have a parameter called 'Id' from the error. You might want to post this on a Java forum or something; this forum's primarily for .Net NHibernate development.

Steve


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 28, 2008 11:25 am 
Regular
Regular

Joined: Wed Aug 15, 2007 7:37 am
Posts: 73
My mistake. Leave the 'type' attributes out of the mapping and Hibernate should work out what the types are. Otherwise you'd be better off posting to the Java forums.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 29, 2008 1:41 am 
Newbie

Joined: Fri Jan 25, 2008 8:32 am
Posts: 15
sorry its not working

SteveMc wrote:
My mistake. Leave the 'type' attributes out of the mapping and Hibernate should work out what the types are. Otherwise you'd be better off posting to the Java forums.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.