-->
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.  [ 7 posts ] 
Author Message
 Post subject: Problems writing to database (hibernate + cocoon)
PostPosted: Mon Jan 19, 2004 10:57 pm 
Regular
Regular

Joined: Mon Jan 19, 2004 10:39 pm
Posts: 84
Location: Nottingham, England
Hi,
I have, for the first time, installed hibernate and followed instructions I managed to get concerning hibernate and cocoon, and of course it doesn't work! When you run the pipeline:

<map:pipelines>

<map:pipeline>
<map:match pattern="test">
<map:generate type="serverpages" src="test.xml"/>
<map:serialize/>
</map:match>
</map:pipeline>

</map:pipelines>


, string s is written to the page sucessfully but nothing is written to my postgresql database table test. I do not get an error message either. What am I doing wrong????

I have the following file, test.xml:

<xsp:page language="java" xmlns:xsp="http://apache.org/xsp">
<xsp:structure>
<xsp:include>test.User</xsp:include>
</xsp:structure>
<page>
<title>Hello</title>
<content>
<xsp:logic>
User usr = new User();
usr.setID("51");
usr.setUserName("beyanet");
usr.setPassword("xyz");
usr.setEmailAddress("hugob@humatix.nl");

usr.add();
String s = usr.getUserName();
</xsp:logic>

<xsp:expr>s</xsp:expr>
</content>
</page>
</xsp:page>

The User.class file is as so:

package test;

import java.util.*;
import net.sf.hibernate.*;
import net.sf.hibernate.cfg.*;


public class User{

private String userID;
private String userName;
private String password;
private String emailAddress;
private Date lastLogon;

public String getID() {
return userID;
}
public void setID(String newUserID) {
userID = newUserID;
}

public String getUserName() {
return (userName == null ? "" : userName);
}
public void setUserName(String userName) {
this.userName = userName;
}

public String getPassword() {
return (password == null ? "" : password);
}
public void setPassword(String password) {
this.password = password;
}

public String getEmailAddress() {
return emailAddress;
}
public void setEmailAddress(String emailAddress) {
this.emailAddress = emailAddress;
}

public Date getLastLogon() {
return lastLogon;
}
public void setLastLogon(Date newLastLogon) {
lastLogon = newLastLogon;
}

public void add() {
try {
Configuration cfg = new Configuration();
cfg.addClass(test.User.class);
SessionFactory sf = cfg.buildSessionFactory();
Session hs = sf.openSession();
hs.save(this);

hs.flush();

hs.close();
hs = null;

sf.close();
sf = null;

cfg = null;
}
catch ( Exception e) {
System.out.println("Exception in Hibernate:" + e.getMessage());
}

}
public String test() {
return "OK";
}
}

Andrew


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 20, 2004 12:15 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
You are not committing or even using any transaction.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject: Problems writing to database (hibernate + cocoon)
PostPosted: Tue Jan 20, 2004 6:34 am 
Regular
Regular

Joined: Mon Jan 19, 2004 10:39 pm
Posts: 84
Location: Nottingham, England
Christian,
the code I posted was gained from a tutorial i got from http://wiki.cocoondev.org/Wiki.jsp?page ... Persistent. If you have any time, would it be possible for you to have a look at this?

thanks


Andrew


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 20, 2004 9:05 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
If you are not using JTA, you have to commit the JDBC database transaction yourself. Use Hibernates Transaction API, see the reference documentation, "Ending a Session".

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject: net.sf.hibernate.MappingException: Error reading resource...
PostPosted: Tue Jan 20, 2004 4:30 pm 
Regular
Regular

Joined: Mon Jan 19, 2004 10:39 pm
Posts: 84
Location: Nottingham, England
Hi,

when trying to run my hibernation app, i am getting the above mentioned error when trying to read test/User.hbm.xml. Any ideas where I am going wrong?

My hbm.xml file, situated in catalina/tomcat/web-inf/classes/test, is:

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

<hibernate-mapping>
<class name="test.User" table="users">
<id name="ID" column="LogonId">
<generator class="sequence">
<param>seq_id_mytable</param>
</generator>
</id>

<property name="userName" column="Name" type="string"/>
<property name="password"/>
<property name="emailAddress"/>
<property name="lastLogon"/>
</class>
</hibernate-mapping>

My class is as follow:

package test;

import java.util.*;
import net.sf.hibernate.*;
import net.sf.hibernate.cfg.*;


public class User{

private String userID;
private String userName;
private String password;
private String emailAddress;
private Date lastLogon;
private SessionFactory _sessions;

public String getID() {
return userID;
}
public void setID(String newUserID) {
userID = newUserID;
}

........................................

public void add() throws HibernateException {
_sessions = new Configuration()
.addClass(test.User.class)
.buildSessionFactory();

Session session = _sessions.openSession();
Transaction tx = null;
try {
tx = session.beginTransaction();
session.save(this);
tx.commit();
}
catch (HibernateException he) {
if (tx!=null) tx.rollback();
throw he;
}
finally {
session.close();
}

}
public String test() {
return "OK";
}
}


The trace is as follows:

org.apache.cocoon.ProcessingException: Exception in ServerPagesGenerator.generate(): net.sf.hibernate.MappingException: Error reading resource: test/User.hbm.xml
at org.apache.cocoon.generation.ServerPagesGenerator.generate(ServerPagesGenerator.java:274)
at org.apache.cocoon.components.pipeline.AbstractProcessingPipeline.processXMLPipeline(AbstractProcessingPipeline.java:557)
at org.apache.cocoon.components.pipeline.impl.AbstractCachingProcessingPipeline.processXMLPipeline(AbstractCachingProcessingPipeline.java:196)
at org.apache.cocoon.components.pipeline.AbstractProcessingPipeline.process(AbstractProcessingPipeline.java:501)
at org.apache.cocoon.components.treeprocessor.sitemap.SerializeNode.invoke(SerializeNode.java:147)
at org.apache.cocoon.components.treeprocessor.AbstractParentProcessingNode.invokeNodes(AbstractParentProcessingNode.java:84)
at org.apache.cocoon.components.treeprocessor.sitemap.PreparableMatchNode.invoke(PreparableMatchNode.java:164)
at org.apache.cocoon.components.treeprocessor.AbstractParentProcessingNode.invokeNodes(AbstractParentProcessingNode.java:108)
at org.apache.cocoon.components.treeprocessor.sitemap.PipelineNode.invoke(PipelineNode.java:163)
at org.apache.cocoon.components.treeprocessor.AbstractParentProcessingNode.invokeNodes(AbstractParentProcessingNode.java:108)
at org.apache.cocoon.components.treeprocessor.sitemap.PipelinesNode.invoke(PipelinesNode.java:152)
at org.apache.cocoon.components.treeprocessor.TreeProcessor.process(TreeProcessor.java:354)
at org.apache.cocoon.components.treeprocessor.TreeProcessor.process(TreeProcessor.java:307)
at org.apache.cocoon.components.treeprocessor.sitemap.MountNode.invoke(MountNode.java:133)
at org.apache.cocoon.components.treeprocessor.AbstractParentProcessingNode.invokeNodes(AbstractParentProcessingNode.java:84)
at org.apache.cocoon.components.treeprocessor.sitemap.PreparableMatchNode.invoke(PreparableMatchNode.java:164)
at org.apache.cocoon.components.treeprocessor.AbstractParentProcessingNode.invokeNodes(AbstractParentProcessingNode.java:108)
at org.apache.cocoon.components.treeprocessor.sitemap.PipelineNode.invoke(PipelineNode.java:163)
at org.apache.cocoon.components.treeprocessor.AbstractParentProcessingNode.invokeNodes(AbstractParentProcessingNode.java:108)
at org.apache.cocoon.components.treeprocessor.sitemap.PipelinesNode.invoke(PipelinesNode.java:152)
at org.apache.cocoon.components.treeprocessor.TreeProcessor.process(TreeProcessor.java:354)
at org.apache.cocoon.components.treeprocessor.TreeProcessor.process(TreeProcessor.java:307)
at org.apache.cocoon.Cocoon.process(Cocoon.java:656)
at org.apache.cocoon.servlet.CocoonServlet.service(CocoonServlet.java:1112)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2415)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:171)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:223)
at org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:261)
at org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:360)
at org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:604)
at org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:562)
at org.apache.jk.common.SocketConnection.runIt(ChannelSocket.java:679)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:619)
at java.lang.Thread.run(Thread.java:554)
Caused by: net.sf.hibernate.MappingException: Error reading resource: test/User.hbm.xml
at net.sf.hibernate.cfg.Configuration.addClass(Configuration.java:325)
at test.User.add(User.java:59)
at org.apache.cocoon.www.userhomes.test_xml.generate(org.apache.cocoon.www.userhomes.test_xml:143)
at org.apache.cocoon.generation.ServerPagesGenerator.generate(ServerPagesGenerator.java:262)
... 55 more
Caused by: net.sf.hibernate.MappingException: org.dom4j.DocumentException: http://hibernate.sourceforge.net/hibern ... ng-2.1.dtd Nested exception: http://hibernate.sourceforge.net/hibern ... ng-2.1.dtd
at net.sf.hibernate.cfg.Configuration.addInputStream(Configuration.java:290)
at net.sf.hibernate.cfg.Configuration.addClass(Configuration.java:322)
... 58 more
Caused by: org.dom4j.DocumentException: http://hibernate.sourceforge.net/hibern ... ng-2.1.dtd Nested exception: http://hibernate.sourceforge.net/hibern ... ng-2.1.dtd
at org.dom4j.io.SAXReader.read(SAXReader.java:358)
at net.sf.hibernate.cfg.Configuration.addInputStream(Configuration.java:281)
... 59 more
net.sf.hibernate.MappingException: Error reading resource: test/User.hbm.xml
at net.sf.hibernate.cfg.Configuration.addClass(Configuration.java:325)
at test.User.add(User.java:59)
at org.apache.cocoon.www.userhomes.test_xml.generate(org.apache.cocoon.www.userhomes.test_xml:143)
at org.apache.cocoon.generation.ServerPagesGenerator.generate(ServerPagesGenerator.java:262)
at org.apache.cocoon.components.pipeline.AbstractProcessingPipeline.processXMLPipeline(AbstractProcessingPipeline.java:557)
at org.apache.cocoon.components.pipeline.impl.AbstractCachingProcessingPipeline.processXMLPipeline(AbstractCachingProcessingPipeline.java:196)
at org.apache.cocoon.components.pipeline.AbstractProcessingPipeline.process(AbstractProcessingPipeline.java:501)
at org.apache.cocoon.components.treeprocessor.sitemap.SerializeNode.invoke(SerializeNode.java:147)
at org.apache.cocoon.components.treeprocessor.AbstractParentProcessingNode.invokeNodes(AbstractParentProcessingNode.java:84)
at org.apache.cocoon.components.treeprocessor.sitemap.PreparableMatchNode.invoke(PreparableMatchNode.java:164)
at org.apache.cocoon.components.treeprocessor.AbstractParentProcessingNode.invokeNodes(AbstractParentProcessingNode.java:108)
at org.apache.cocoon.components.treeprocessor.sitemap.PipelineNode.invoke(PipelineNode.java:163)
at org.apache.cocoon.components.treeprocessor.AbstractParentProcessingNode.invokeNodes(AbstractParentProcessingNode.java:108)
at org.apache.cocoon.components.treeprocessor.sitemap.PipelinesNode.invoke(PipelinesNode.java:152)
at org.apache.cocoon.components.treeprocessor.TreeProcessor.process(TreeProcessor.java:354)
at org.apache.cocoon.components.treeprocessor.TreeProcessor.process(TreeProcessor.java:307)
at org.apache.cocoon.components.treeprocessor.sitemap.MountNode.invoke(MountNode.java:133)
at org.apache.cocoon.components.treeprocessor.AbstractParentProcessingNode.invokeNodes(AbstractParentProcessingNode.java:84)
at org.apache.cocoon.components.treeprocessor.sitemap.PreparableMatchNode.invoke(PreparableMatchNode.java:164)
at org.apache.cocoon.components.treeprocessor.AbstractParentProcessingNode.invokeNodes(AbstractParentProcessingNode.java:108)
at org.apache.cocoon.components.treeprocessor.sitemap.PipelineNode.invoke(PipelineNode.java:163)
at org.apache.cocoon.components.treeprocessor.AbstractParentProcessingNode.invokeNodes(AbstractParentProcessingNode.java:108)
at org.apache.cocoon.components.treeprocessor.sitemap.PipelinesNode.invoke(PipelinesNode.java:152)
at org.apache.cocoon.components.treeprocessor.TreeProcessor.process(TreeProcessor.java:354)
at org.apache.cocoon.components.treeprocessor.TreeProcessor.process(TreeProcessor.java:307)
at org.apache.cocoon.Cocoon.process(Cocoon.java:656)
at org.apache.cocoon.servlet.CocoonServlet.service(CocoonServlet.java:1112)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2415)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:171)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:223)
at org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:261)
at org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:360)
at org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:604)
at org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:562)
at org.apache.jk.common.SocketConnection.runIt(ChannelSocket.java:679)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:619)
at java.lang.Thread.run(Thread.java:554)
Caused by: net.sf.hibernate.MappingException: org.dom4j.DocumentException: http://hibernate.sourceforge.net/hibern ... ng-2.1.dtd Nested exception: http://hibernate.sourceforge.net/hibern ... ng-2.1.dtd
at net.sf.hibernate.cfg.Configuration.addInputStream(Configuration.java:290)
at net.sf.hibernate.cfg.Configuration.addClass(Configuration.java:322)
... 58 more
Caused by: org.dom4j.DocumentException: http://hibernate.sourceforge.net/hibern ... ng-2.1.dtd Nested exception: http://hibernate.sourceforge.net/hibern ... ng-2.1.dtd
at org.dom4j.io.SAXReader.read(SAXReader.java:358)
at net.sf.hibernate.cfg.Configuration.addInputStream(Configuration.java:281)
... 59 more


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 20, 2004 4:36 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
There must be some other nested exception. Try to run Hibernate without cocoon or try to find the real exception error message.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject: problem parsing configuration/test/hibernate.cfg.xml
PostPosted: Wed Jan 21, 2004 4:29 pm 
Regular
Regular

Joined: Mon Jan 19, 2004 10:39 pm
Posts: 84
Location: Nottingham, England
Hi,
I am getting the above message when I try and run hibernate from cocoon. Can anyone tell me what I am doing incorrectly?

1. class snippet:

public void add(){
try {
Configuration cfg = new Configuration()
.configure ("/test/hibernate.cfg.xml");
SessionFactory sf = cfg.buildSessionFactory();
Session session = sf.openSession();
Transaction transaction = session.beginTransaction();

User usr = new User();
usr.setID("143");
usr.setUserName("x");
usr.setPassword("x");
usr.setEmailAddress("test@hotmail.com");
usr.setLastLogon(newDate);

session.save(usr);
session.flush();
transaction.commit();

session.close();
session = null;

sf.close();
sf = null;

cfg = null;

}
catch ( Exception e) {
state = "Exception in Hibernate: " + e.getMessage();
}

2. hibernate.cfg.xml

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 2.0//EN"

"http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd";>


<hibernate-configuration>

<session-factory>
<property name="connection.driver_class">org.postgresql.Driver</property>
<property name="connection.url">jdbc:postgresql://localhost:5432/test</property>
<property name="connection.username">x</property>
<property name="connection.password">x</property>
<property name="show_sql">false</property>
<property name="use_outer_join">true</property>
<property name="dialect">net.sf.hibernate.dialect.PostgreSQLDialect</property>

<mapping resource="User2.hbm.xml"/>


</session-factory>

</hibernate-configuration>

3. Users2.hbm.xml

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

<hibernate-mapping>
<class name="test.User" table="users">
<id name="ID" type="string" unsaved-value="null">
<column name="LogonID" sql-type="char(32)" not-null="true"/>
<generator class="uuid.hex"/>
</id>

<property name="userName" column="Name" type="string"/>
<property name="password" column="Password" type="string"/>
<property name="emailAddress" column="EmailAddress" type="string"/>
<property name="lastLogon" column="Lastlogon" type="date"/>
</class>
</hibernate-mapping>

Andrew


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 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.