Creating CMR

I'm trying to create CMR with JBoss and MySQL but I cannot make the relations appear in the database. I'd like something to explain from the begining how to create this kind of relations. I'm a beginner and I'm doing a J2EE application that needs some relations in the db.

I'm using JBoss, MySQL and xDoclet.

[326 byte] By [sirynxa] at [2007-11-27 4:51:49]
# 1

Not an answer, but I was just looking to solve this very problem myself. Same kit: JBoss, Eclipse, XDoclet, MySQL

Best I have come up with is this link:

http://www.daimi.au.dk/~ntj/j2ee/xdoclet.cmp.relationships.php

Haven't tried it yet, as I've given up for a while, but it looks like what we are both after.

Interesting (probably not) I have 2 problems. I cant get AUTO_INCREMENT to work.

Paul

PCampbella at 2007-7-12 10:05:37 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 2

Thank you for your help, I've tried to do what the link you give me but it doesn't work. The field that must have the relational value isn't created. I'd like if you do too to use this post to put what we find, so that we can find the solution together. I'm going to find more. I'm also interested in auto-increment. There is a jboss tag to do I'll find it and post it here.

sirynxa at 2007-7-12 10:05:37 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 3

I tried the page last night and it worked. I made my own project and created the EJB's with his source code individually, then did my own XDoclet and Packaging and deployed it and it worked.

I also just tried to...

1.Download his zip file: http://www.daimi.au.dk/~ntj/download/ntj.examples.src.zip

2. Unzip into my Eclipse workspace

3. Use "Import... Projects into workspace" to import the unzipped project.

4. Enabled XDoclet and Packaging configurations.

5. Edited the XDoclet "jboss" entry and added my MySQL DataSource.

6. Ran XDoclet and Packaging.

7. Deployed the EAR

8. Deployed the JAR

It worked.

00:48:53,737 INFO [EARDeployer] Init J2EE application: file:/opt/jboss-3.2.5/server/default/deploy/ntj.examples.app.ear

00:49:09,764 INFO [EjbModule] Deploying Address

00:49:09,810 INFO [EjbModule] Deploying RoomType

00:49:09,825 INFO [EjbModule] Deploying House

00:49:09,838 INFO [EjbModule] Deploying Person

00:49:09,850 INFO [EjbModule] Deploying Room

00:49:09,864 INFO [EjbModule] Deploying Car

00:49:14,857 INFO [Car] Created table 'Car' successfully.

00:49:14,881 INFO [Room] Created table 'Room' successfully.

00:49:14,905 INFO [House] Created table 'House' successfully.

00:49:14,937 INFO [Address] Created table 'Address' successfully.

00:49:14,991 INFO [Person] Created table 'Person' successfully.

00:49:15,008 INFO [Person] Created table 'users_to_cars' successfully.

00:49:15,029 INFO [RoomType] Created table 'RoomType' successfully.

00:49:15,040 INFO [RoomType] Created table 'rooms_to_roomtypes' successfully.

00:49:15,043 INFO [EJBDeployer] Deployed: file:/opt/jboss-3.2.5/server/default/tmp/deploy/tmp8145ntj.examples.app.ear-contents/ntj.examples.ejb.jar

00:49:15,217 INFO [EARDeployer] Started J2EE application: file:/opt/jboss-3.2.5/server/default/deploy/ntj.examples.app.ear

The MySQL tables are created successfully.

I have not tried to insert records yet though.

In my other project, I had a problem when I inserted records into a table with an auto increment field. I found a solution to the problem on the web and adding:

* @jboss.entity-command

*name="mysql-get-generated-keys"

*class="org.jboss.ejb.plugins.cmp.jdbc.keygen.JDBCMySQLCreateCommand"

... the class="" bit. Solved the problem with NULL keys etc.

I'm not sure which versions, or even which apps you are using, but the page in question does indeed work.

Good luck with your attempt :)

Paul

PCampbella at 2007-7-12 10:05:37 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 4

Thank you for your help, I've downloaded the source code of the example you put and I realised that I was getting the wrong information en fk-column, now I have my field well-created. Thank you again for your help. I'm looking for finding the solution to the auto_increment field, I think is possible to make it with a xDoclet tag. When I know something, I'll post it. Please post whatever you discover about the topic of auto_increment. Thank you again.

sirynxa at 2007-7-12 10:05:37 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 5

I've get an auto_increment field. It's very easy to do with xDoclet, you have to add the next line to the definition of the field you want to make auto_increment

@jboss.persistence auto-increment="true"

By doing that, you'll get an auto-increment field. I've tested that in my project and using mySQL 5 and JBoss 4.0.5 it works. Thak you for your help.

sirynxa at 2007-7-12 10:05:38 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...