-->
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.  [ 11 posts ] 
Author Message
 Post subject: Hibernate with EJB BMP example with DTO Desing Patterm
PostPosted: Fri Sep 19, 2003 3:14 pm 
Newbie

Joined: Fri Sep 19, 2003 2:57 pm
Posts: 10
Hi,

I'm new with hibernate and I want to view
an example on how to use an EJB with hibernate and the DTO Design Pattern,

Does any have something?

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 19, 2003 4:13 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Not that I've seen, but I use this type of setup. What exactly were you needing to know?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 19, 2003 4:56 pm 
Newbie

Joined: Fri Sep 19, 2003 2:57 pm
Posts: 10
I don't have much clear how to use these 3 things together so if I see some little example will be very usefull.

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 19, 2003 9:54 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Sorry, missed the BMP. I don't use entiy beans. Just session ejbs.

Mind if I ask why you want to use entity beans, considering you are seemingly already planning on using Hibernate?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 20, 2003 11:21 am 
Newbie

Joined: Fri Sep 19, 2003 2:57 pm
Posts: 10
I got it.

Do you have some good example using Session Beans with hibernate?

Then I will use struts for the MVC part.

Thanks


Top
 Profile  
 
 Post subject: Example Session Bean
PostPosted: Sat Sep 20, 2003 2:12 pm 
Beginner
Beginner

Joined: Fri Sep 05, 2003 7:21 am
Posts: 27
Location: Sweden
I suggest that you look at this as a template for writing your session beans: http://www.studenter.hb.se/~arch/files/ ... eBean.java

The idea is simple: one SB per entity class (one "service" for adding, updating, finding and removing instances per class)

Note: the latest version of hbm2java (currently only available from CVS) is capable of generating these automatically for you, leaving only the presentation tier code to be written (assuming you use middlegen to generate the .hbm.xml mapping files)

Now how about that - nice, huh? :)


Top
 Profile  
 
 Post subject: RE:Hibernate with EJB BMP example with DTO Desing Patterm
PostPosted: Sun Sep 21, 2003 12:54 am 
Beginner
Beginner

Joined: Sun Sep 21, 2003 12:19 am
Posts: 40
carniz showed you the power of using midgen/xdoclet.


But here is my perspective without extra code generation step.

You can check junitejb package listed on sourceforge, the EJBTestRunnerBean will give you an idea how to integrate with Hibernate with Sessionbean.

Here is a simple code section from my code when I evaled hibernate. Here I did not put the sessionfactory to JNDI, you can certainly do so. You can even throw the init process into JMX if you want to.
[code]
public class TestCase extends EJBTestCase {
....
public static void exportSchema(String[] files) throws Exception {
Configuration cfg = new Configuration();
Properties p = new Properties();
.....
cfg = cfg.addProperties(p);
for (int i = 0; i < files.length; i++) {
cfg.addResource("res/or_map/" + files[i], TestCase.class.getClassLoader());
}

dialect = Dialect.getDialect(p);
new SchemaExport(cfg).create(true, true);

sessions = cfg.buildSessionFactory();
}
public void setUpEJB() throws Exception {
TestCase.exportSchema(
new String[]{
"base.hbm.xml"
}
);
}
public void tearDownEJB() throws Exception {
sessions.close();
}

public void testSimpleCreate() throws Exception {
Session s = sessions.openSession();
Transaction t = s.beginTransaction();
.....
t.commit();
s.close();
}
[/code]

Hope this helps.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 22, 2003 9:55 am 
Newbie

Joined: Fri Sep 19, 2003 2:57 pm
Posts: 10
I tried to use Middlegen for generate the hbm files but the version b1 doesn't have the plugin.

Where I can find this plugin for middlegen?

thanks


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 23, 2003 1:33 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Quote:
Where I can find this plugin for middlegen?


Hibernate downloads page


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 24, 2003 10:20 am 
Newbie

Joined: Fri Sep 19, 2003 2:57 pm
Posts: 10
I use the middlegen plugin for hibernate to generate the hbm files

<hibernate
destination="${build.gen-src.dir}/main"
package="hibernate"
/>

then I use the hbm2java tools to generate the .java files but I have many errors.

<target name="hbm2java" depends="middlegen"
description="Generate ValueObject From Mapping Files">
<java classname="net.sf.hibernate.tool.hbm2java.CodeGenerator"
classpathref="xdoclet.path">
<arg value="--output=${{build.gen-src.dir}/main/hibernate"/>
<arg value="${build.gen-src.dir}/main/hibernate/UserTable.hbm.xml"/>
</java>
</target>

When I look to them, the problem is the hbm generated by middlegen.

Some suggestions?

Thanks


[java] (hbm2java.CodeGenerator 43 ) Error parsing XML: file:/C:/Development/Monit
oring/app-dev-v3.1/build/gen-src/main/hibernate/UserTable.hbm.xml(28)
[java] org.xml.sax.SAXParseException: Attribute "generator-class" must be declared for element
type "id".
[java] at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source
)
[java] at org.apache.xerces.util.ErrorHandlerWrapper.error(Unknown Source)
[java] at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
[java] at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
[java] at org.apache.xerces.impl.dtd.XMLDTDValidator.addDTDDefaultAttrsAndValidate(Unknown
Source)
[java] at org.apache.xerces.impl.dtd.XMLDTDValidator.handleStartElement(Unknown Source)
[java] at org.apache.xerces.impl.dtd.XMLDTDValidator.startElement(Unknown Source)
[java] at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
[java] at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.d
ispatch(Unknown Source)
[java] at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source
)
[java] at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
[java] at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source)
[java] at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
[java] at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
[java] at org.jdom.input.SAXBuilder.build(SAXBuilder.java:354)
[java] at org.jdom.input.SAXBuilder.build(SAXBuilder.java:707)
[java] at org.jdom.input.SAXBuilder.build(SAXBuilder.java:689)
[java] at net.sf.hibernate.tool.hbm2java.CodeGenerator.main(CodeGenerator.java:93)
[java] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[java] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
[java] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java
:25)
[java] at java.lang.reflect.Method.invoke(Method.java:324)
[java] at org.apache.tools.ant.taskdefs.ExecuteJava.run(ExecuteJava.java:208)
[java] at org.apache.tools.ant.taskdefs.ExecuteJava.execute(ExecuteJava.java:150)
[java] at org.apache.tools.ant.taskdefs.Java.run(Java.java:443)
[java] at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:163)
[java] at org.apache.tools.ant.taskdefs.Java.execute(Java.java:108)
[java] at org.apache.tools.ant.Task.perform(Task.java:341)
[java] at org.apache.tools.ant.Target.execute(Target.java:309)
[java] at org.apache.tools.ant.Target.performTasks(Target.java:336)
[java] at org.apache.tools.ant.Project.executeTarget(Project.java:1339)
[java] at org.apache.tools.ant.Project.executeTargets(Project.java:1255)
[java] at org.apache.tools.ant.Main.runBuild(Main.java:609)
[java] at org.apache.tools.ant.Main.start(Main.java:196)
[java] at org.apache.tools.ant.Main.main(Main.java:235)
[java] (hbm2java.CodeGenerator 43 ) Error parsing XML: file:/C:/Development/Monit
oring/app-dev-v3.1/build/gen-src/main/hibernate/UserTable.hbm.xml(28)
[java] org.xml.sax.SAXParseException: Attribute "not-null" must be declared for element type "i
d".
[java] at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source
)
[java] at org.apache.xerces.util.ErrorHandlerWrapper.error(Unknown Source)
[java] at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
[java] at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
[java] at org.apache.xerces.impl.dtd.XMLDTDValidator.addDTDDefaultAttrsAndValidate(Unknown
Source)
[java] at org.apache.xerces.impl.dtd.XMLDTDValidator.handleStartElement(Unknown Source)
[java] at org.apache.xerces.impl.dtd.XMLDTDValidator.startElement(Unknown Source)
[java] at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
[java] at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.d
ispatch(Unknown Source)
[java] at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source
)
[java] at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
[java] at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source)
[java] at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
[java] at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
[java] at org.jdom.input.SAXBuilder.build(SAXBuilder.java:354)
[java] at org.jdom.input.SAXBuilder.build(SAXBuilder.java:707)
[java] at org.jdom.input.SAXBuilder.build(SAXBuilder.java:689)
[java] at net.sf.hibernate.tool.hbm2java.CodeGenerator.main(CodeGenerator.java:93)
[java] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[java] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
[java] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java
:25)
[java] at java.lang.reflect.Method.invoke(Method.java:324)
[java] at org.apache.tools.ant.taskdefs.ExecuteJava.run(ExecuteJava.java:208)
[java] at org.apache.tools.ant.taskdefs.ExecuteJava.execute(ExecuteJava.java:150)
[java] at org.apache.tools.ant.taskdefs.Java.run(Java.java:443)
[java] at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:163)
[java] at org.apache.tools.ant.taskdefs.Java.execute(Java.java:108)
[java] at org.apache.tools.ant.Task.perform(Task.java:341)
[java] at org.apache.tools.ant.Target.execute(Target.java:309)
[java] at org.apache.tools.ant.Target.performTasks(Target.java:336)
[java] at org.apache.tools.ant.Project.executeTarget(Project.java:1339)
[java] at org.apache.tools.ant.Project.executeTargets(Project.java:1255)
[java] at org.apache.tools.ant.Main.runBuild(Main.java:609)
[java] at org.apache.tools.ant.Main.start(Main.java:196)
[java] at org.apache.tools.ant.Main.main(Main.java:235)
[java] (hbm2java.CodeGenerator 43 ) Error parsing XML: file:/C:/Development/Monit
oring/app-dev-v3.1/build/gen-src/main/hibernate/UserTable.hbm.xml(133)
[java] org.xml.sax.SAXParseException: The element type "property" must be terminated by the mat
ching end-tag "</property>".
[java] at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source
)
[java] at org.apache.xerces.util.ErrorHandlerWrapper.fatalError(Unknown Source)
[java] at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
[java] at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
[java] at org.apache.xerces.impl.XMLScanner.reportFatalError(Unknown Source)
[java] at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanEndElement(Unknown Source)
[java] at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.d
ispatch(Unknown Source)
[java] at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source
)
[java] at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
[java] at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source)
[java] at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
[java] at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
[java] at org.jdom.input.SAXBuilder.build(SAXBuilder.java:354)
[java] at org.jdom.input.SAXBuilder.build(SAXBuilder.java:707)
[java] at org.jdom.input.SAXBuilder.build(SAXBuilder.java:689)
[java] at net.sf.hibernate.tool.hbm2java.CodeGenerator.main(CodeGenerator.java:93)
[java] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[java] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
[java] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java
:25)
[java] at java.lang.reflect.Method.invoke(Method.java:324)
[java] at org.apache.tools.ant.taskdefs.ExecuteJava.run(ExecuteJava.java:208)
[java] at org.apache.tools.ant.taskdefs.ExecuteJava.execute(ExecuteJava.java:150)
[java] at org.apache.tools.ant.taskdefs.Java.run(Java.java:443)
[java] at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:163)
[java] at org.apache.tools.ant.taskdefs.Java.execute(Java.java:108)
[java] at org.apache.tools.ant.Task.perform(Task.java:341)
[java] at org.apache.tools.ant.Target.execute(Target.java:309)
[java] at org.apache.tools.ant.Target.performTasks(Target.java:336)
[java] at org.apache.tools.ant.Project.executeTarget(Project.java:1339)
[java] at org.apache.tools.ant.Project.executeTargets(Project.java:1255)
[java] at org.apache.tools.ant.Main.runBuild(Main.java:609)
[java] at org.apache.tools.ant.Main.start(Main.java:196)
[java] at org.apache.tools.ant.Main.main(Main.java:235)
[java] org.jdom.JDOMException: Error on line 133 of document file:/C:/Development/Monitoring/ap
p-dev-v3.1/build/gen-src/main/hibernate/UserTable.hbm.xml: The element type "property" must be termi
nated by the matching end-tag "</property>".
[java] at org.jdom.input.SAXBuilder.build(SAXBuilder.java:363)
[java] at org.jdom.input.SAXBuilder.build(SAXBuilder.java:707)
[java] at org.jdom.input.SAXBuilder.build(SAXBuilder.java:689)
[java] at net.sf.hibernate.tool.hbm2java.CodeGenerator.main(CodeGenerator.java:93)
[java] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[java] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
[java] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java
:25)
[java] at java.lang.reflect.Method.invoke(Method.java:324)
[java] at org.apache.tools.ant.taskdefs.ExecuteJava.run(ExecuteJava.java:208)
[java] at org.apache.tools.ant.taskdefs.ExecuteJava.execute(ExecuteJava.java:150)
[java] at org.apache.tools.ant.taskdefs.Java.run(Java.java:443)
[java] at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:163)
[java] at org.apache.tools.ant.taskdefs.Java.execute(Java.java:108)
[java] at org.apache.tools.ant.Task.perform(Task.java:341)
[java] at org.apache.tools.ant.Target.execute(Target.java:309)
[java] at org.apache.tools.ant.Target.performTasks(Target.java:336)
[java] at org.apache.tools.ant.Project.executeTarget(Project.java:1339)
[java] at org.apache.tools.ant.Project.executeTargets(Project.java:1255)
[java] at org.apache.tools.ant.Main.runBuild(Main.java:609)
[java] at org.apache.tools.ant.Main.start(Main.java:196)
[java] at org.apache.tools.ant.Main.main(Main.java:235)
[java] Caused by: org.xml.sax.SAXParseException: The element type "property" must be terminated
by the matching end-tag "</property>".
[java] at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
[java] at org.jdom.input.SAXBuilder.build(SAXBuilder.java:354)
[java] ... 20 more
[java] Caused by: org.xml.sax.SAXParseException: The element type "property" must be terminated
by the matching end-tag "</property>".
[java] at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
[java] at org.jdom.input.SAXBuilder.build(SAXBuilder.java:354)
[java] at org.jdom.input.SAXBuilder.build(SAXBuilder.java:707)
[java] at org.jdom.input.SAXBuilder.build(SAXBuilder.java:689)
[java] at net.sf.hibernate.tool.hbm2java.CodeGenerator.main(CodeGenerator.java:93)
[java] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[java] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
[java] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java
:25)
[java] at java.lang.reflect.Method.invoke(Method.java:324)
[java] at org.apache.tools.ant.taskdefs.ExecuteJava.run(ExecuteJava.java:208)
[java] at org.apache.tools.ant.taskdefs.ExecuteJava.execute(ExecuteJava.java:150)
[java] at org.apache.tools.ant.taskdefs.Java.run(Java.java:443)
[java] at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:163)
[java] at org.apache.tools.ant.taskdefs.Java.execute(Java.java:108)
[java] at org.apache.tools.ant.Task.perform(Task.java:341)
[java] at org.apache.tools.ant.Target.execute(Target.java:309)
[java] at org.apache.tools.ant.Target.performTasks(Target.java:336)
[java] at org.apache.tools.ant.Project.executeTarget(Project.java:1339)
[java] at org.apache.tools.ant.Project.executeTargets(Project.java:1255)
[java] at org.apache.tools.ant.Main.runBuild(Main.java:609)
[java] at org.apache.tools.ant.Main.start(Main.java:196)
[java] at org.apache.tools.ant.Main.main(Main.java:235)
[java] Caused by: org.xml.sax.SAXParseException: The element type "property" must be terminated
by the matching end-tag "</property>".
[java] at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
[java] at org.jdom.input.SAXBuilder.build(SAXBuilder.java:354)
[java] at org.jdom.input.SAXBuilder.build(SAXBuilder.java:707)
[java] at org.jdom.input.SAXBuilder.build(SAXBuilder.java:689)
[java] at net.sf.hibernate.tool.hbm2java.CodeGenerator.main(CodeGenerator.java:93)
[java] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[java] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
[java] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java
:25)
[java] at java.lang.reflect.Method.invoke(Method.java:324)
[java] at org.apache.tools.ant.taskdefs.ExecuteJava.run(ExecuteJava.java:208)
[java] at org.apache.tools.ant.taskdefs.ExecuteJava.execute(ExecuteJava.java:150)
[java] at org.apache.tools.ant.taskdefs.Java.run(Java.java:443)
[java] at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:163)
[java] at org.apache.tools.ant.taskdefs.Java.execute(Java.java:108)
[java] at org.apache.tools.ant.Task.perform(Task.java:341)
[java] at org.apache.tools.ant.Target.execute(Target.java:309)
[java] at org.apache.tools.ant.Target.performTasks(Target.java:336)
[java] at org.apache.tools.ant.Project.executeTarget(Project.java:1339)
[java] at org.apache.tools.ant.Project.executeTargets(Project.java:1255)
[java] at org.apache.tools.ant.Main.runBuild(Main.java:609)
[java] at org.apache.tools.ant.Main.start(Main.java:196)
[java] at org.apache.tools.ant.Main.main(Main.java:235)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 24, 2003 12:17 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
I would suggest you Post one of the hbm files you have generated but from what I can see you may not have selected a reasonable ID generation strategy. Try for now just using the assigned option and go from there. You do need to understand how hibernate works to some degree to understand the GUI options.


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