You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-user@db.apache.org by Michael Harrison <go...@alumni.princeton.edu> on 2003/03/31 01:22:07 UTC

newbie questions about ojb setup with my database

Hello, all. I'm very new to OJB, and I'm very excited about it. I've 
been reading the extensive documentation at db.apache.org, and I've 
managed to get OJB set up. I have a question, however, about configuring 
OJB to work with my MySQL database.

I'm not only new to OJB, but new to Ant and building (I've been in the 
interpreted throw-away scripting world for a long time), so part of what 
I need to learn stems from my ignorence there. After I downloaded OJB 
and expanded everything, I followed the instructions at platforms.html 
to set up a test database. I "switched on" the line for the MySQL 
profile. I also edited the mysql.profile with the proper jdbc url info, 
username, password, etc.  I understood that two things were happening at 
once: 1) the build process was creating the necessary OJB internal 
tables, not all of which (or any necessarily?) are required; and 2) the 
build process was creating and populating tables for the example 
database, which simulates an actual production db.

Here are my questions:

When I want to use OJB to connect to my own production db, do I need to 
run the build again, against a new build.xml file; or is it already set 
up to use MySQL, and I only have to alter a few configuration files for 
the new jdbc url, password, etc?

The file repository_database.xml contains a jdbc-connection-descriptor 
with attributes like jcd-alias="@JCD_ALIAS@"  I'm not familiar with 
@foo@ notation--does this mean there is supposed to be a 
previously-defined value for some JCD_ALIAS token or entity? Or is this 
a placeholder that I should replace with real values?

Also, what is the relationship between the repository_database.xml file 
and the values I set in mysql.profile before the build? Is the build 
supposed to write this XML file out?

If I need to rerun the build, how do I avoid creating all the example 
tables?

I apologize for the newbie questions. I'm climbing a steep learning 
curve, and I'm probably not being as patient as I should be. Help me 
out, and I promise I'll find much more interesting questions soon enough.

Best Regards,

Michael

||


Re: newbie questions about ojb setup with my database

Posted by Oki DZ <ok...@pindad.com>.
On Sun, Mar 30, 2003 at 06:22:07PM -0500, Michael Harrison wrote:
> When I want to use OJB to connect to my own production db, do I need to 
> run the build again, against a new build.xml file; or is it already set 

No, you don't need to run the build again.

> up to use MySQL, and I only have to alter a few configuration files for 
> the new jdbc url, password, etc?

I could get it run in standalone-mode by having the following xml files 
in a directory (the program's home):
repository.xml
repository_database.xml
repository_internal.xml
repository_user.xml

The contents of repository.xml, are basically:
<descriptor-repository version="1.0" isolation-level="read-uncommitted">
    &database;
    &internal;
    &user;
</descriptor-repository>
 
> The file repository_database.xml contains a jdbc-connection-descriptor 
> with attributes like jcd-alias="@JCD_ALIAS@"  I'm not familiar with 
> @foo@ notation--does this mean there is supposed to be a 
> previously-defined value for some JCD_ALIAS token or entity? Or is this 
> a placeholder that I should replace with real values?

You can change it to "default":
<!-- this connection was used as the default one within OJB -->
<jdbc-connection-descriptor
  jcd-alias="default"
  default-connection="true"
  platform="MySQL"
  jdbc-level="2.0"
...

Later, you can get that default connection by
PersistenceBroker broker = 
	PersistenceBrokerFactory.defaultPersistenceBroker();

To have the repository.xml getting read, make sure that your program's 
home is set to the directory where that repository resides. This can be 
done via ant:
  <target name="execute" depends="compile" description="execute the 
app">
    <exec dir="${ojbhome}" executable="${javahome}/bin/java">
      <arg line="-classpath 
${distdir}:${commons-beanutils-jar}:${commons-collections-jar}:${commons-dbcp-jar}:${commons-lang-jar}:${commons-logging-jar}:${commons-pool-jar}:${ojb-jar}:${spy-jar}:${xerces-jar}:${j2ee-jar}"/>
      <arg line="com.<your main package>.Main"/>
    </exec>
  </target>

Somewhere above, ojbhome was set to the program's home dir.
 
> Also, what is the relationship between the repository_database.xml file 
> and the values I set in mysql.profile before the build? 

It would provide you with a connection defined in the file.

> Is the build  supposed to write this XML file out?

Yes; overwriting it, I mean.

Oki


OT:Best Practice for O/R-Mapping

Posted by Joerg Lensing <in...@softcon-lensing.de>.
Hi,
is there any good book/site/newsgroup for O/R-Mapping?
I'm asking this for performance/maintaining

joerg


something not working as I expect it to

Posted by Brill Pappin <br...@roguerobotics.com>.
I have a fairly simple object, who's ID I need to access.

in my descriptor for the object, I have the id field set to auto-increment
and as a primary key.

In the class, the id is initialized to -1 (All my classes, in all my
libraries initialize all instance members, even if only to null. this is
part of our standards and good programming practice in general).

What I am expecting, is that because I've set the id to auto-increment in
the descriptor, that when I create a new class, the ID is auto generated...
however what I get is the default value of the new object (-1 in this case).
Can I force ID's for a particular object to always be generated by the
database?

If not, what is the recommended way to force that generation?

I need the ID's because I'm working in a web environment and the id's are
often called from remote applications... not to mention legacy data/apps ;)
So, I need the ID field, but I also want the system to generate it for new
objects.

- Brill Pappin



Re: newbie questions about ojb setup with my database

Posted by Brill Pappin <br...@roguerobotics.com>.
I've got a similar questions about those tokens.

I'm at the point of deploying the libs and a few tests to my development
server, however the tests seems to be failing because the tokens are not
being replaced.

I assume in the following (from repository-database.xml) that those values
are supposed to come from the OJB.properties file, however in my test output
it looks like they are not getting parsed.

<jdbc-connection-descriptor
     jcd-alias="@JCD_ALIAS@"
     default-connection="true"
     platform="@DBMS_NAME@"
     jdbc-level="@JDBC_LEVEL@"
     driver="@DRIVER_NAME@"
     protocol="@URL_PROTOCOL@"
     subprotocol="@URL_SUBPROTOCOL@"
     dbalias="@URL_DBALIAS@"
     username="@USER_NAME@"
     password="@USER_PASSWD@"
     batch-mode="false"
        useAutoCommit="1"
        ignoreAutoCommitExceptions="false"
     >

I imagine this is a common problem, so can anyone tell me where the failure
originates, or how to solve it?

- Brill Pappin

----- Original Message -----
From: "Michael Harrison" <go...@alumni.princeton.edu>
To: <oj...@db.apache.org>
Sent: Sunday, March 30, 2003 6:22 PM
Subject: newbie questions about ojb setup with my database


> Hello, all. I'm very new to OJB, and I'm very excited about it. I've
> been reading the extensive documentation at db.apache.org, and I've
> managed to get OJB set up. I have a question, however, about configuring
> OJB to work with my MySQL database.
>
> I'm not only new to OJB, but new to Ant and building (I've been in the
> interpreted throw-away scripting world for a long time), so part of what
> I need to learn stems from my ignorence there. After I downloaded OJB
> and expanded everything, I followed the instructions at platforms.html
> to set up a test database. I "switched on" the line for the MySQL
> profile. I also edited the mysql.profile with the proper jdbc url info,
> username, password, etc.  I understood that two things were happening at
> once: 1) the build process was creating the necessary OJB internal
> tables, not all of which (or any necessarily?) are required; and 2) the
> build process was creating and populating tables for the example
> database, which simulates an actual production db.
>
> Here are my questions:
>
> When I want to use OJB to connect to my own production db, do I need to
> run the build again, against a new build.xml file; or is it already set
> up to use MySQL, and I only have to alter a few configuration files for
> the new jdbc url, password, etc?
>
> The file repository_database.xml contains a jdbc-connection-descriptor
> with attributes like jcd-alias="@JCD_ALIAS@"  I'm not familiar with
> @foo@ notation--does this mean there is supposed to be a
> previously-defined value for some JCD_ALIAS token or entity? Or is this
> a placeholder that I should replace with real values?
>
> Also, what is the relationship between the repository_database.xml file
> and the values I set in mysql.profile before the build? Is the build
> supposed to write this XML file out?
>
> If I need to rerun the build, how do I avoid creating all the example
> tables?
>
> I apologize for the newbie questions. I'm climbing a steep learning
> curve, and I'm probably not being as patient as I should be. Help me
> out, and I promise I'll find much more interesting questions soon enough.
>
> Best Regards,
>
> Michael
>
> ||
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
>
>