You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Eric Lazarus <er...@yahoo.com> on 2009/10/21 02:00:55 UTC

Cayenne and H2 on the desktop

Folks

Thanks for you folks direction on using H2 as our database but we are a bit stuck on how to do it. We are moving toward using Cayenne 3.0M6 and H2 for the desktop version of an application that should be as idiot proof as possible. We want for the end user to not have to understand that there is a database there at all. 

Any suggestions about how we should configure things? For example, should we configure H2 to run embedded if we don't want the end user to have to be aware of it? How DO we configure it that way? What should we be reading to figure out how to do that? I am not even sure we understand what it means to run "embeded." Does that mean that that database is in the same VM? That we don't go via JDBC at all? 

Also, we are trying to load a postgres dump into H2 and am failing because H2 does not support the COPY statement. I have tried enabling postgres compatibility mode by appending ';MODE=PostgreSQL' to my database url. This results in a error message stating 'File not found 'backup.sql'. I tried putting my dump in a file by that name and got the same message.

I also tried sticking 'SET MODE PostgreSQL ;' at the top of my SQL dump file. This had no effect the script still abended with a syntax error on the COPY command.

Where the best place to ask H2 questions? Is there an IRC room? A list serve? 

thanks! 

Eric

+1 (917) 589-6579


      

Re: Cayenne and H2 on the desktop

Posted by Mike Kienenberger <mk...@gmail.com>.
If I recall, the "jdbc:h2:path" url will accept any username/password
you give it and create the database appropriately.  You don't have to
use the default "sa"/(blank)


On Tue, Oct 20, 2009 at 8:15 PM, Michael Gentry <mg...@masslight.net> wrote:
> An embedded database is one that runs internally instead of requiring
> a separate database server.  This makes it convenient for standalone
> applications.
>
> For the database connection itself, though, you'd want something like:
>
> JDBC URL: jdbc:h2:~/mydb
> Username: sa
> Password: <blank>
>
> As for PostgreSQL support in H2, I don't know anything about that.  Sorry.
>
> mrg
>
>
> On Tue, Oct 20, 2009 at 8:00 PM, Eric Lazarus <er...@yahoo.com> wrote:
>> Folks
>>
>> Thanks for you folks direction on using H2 as our database but we are a bit stuck on how to do it. We are moving toward using Cayenne 3.0M6 and H2 for the desktop version of an application that should be as idiot proof as possible. We want for the end user to not have to understand that there is a database there at all.
>>
>> Any suggestions about how we should configure things? For example, should we configure H2 to run embedded if we don't want the end user to have to be aware of it? How DO we configure it that way? What should we be reading to figure out how to do that? I am not even sure we understand what it means to run "embeded." Does that mean that that database is in the same VM? That we don't go via JDBC at all?
>>
>> Also, we are trying to load a postgres dump into H2 and am failing because H2 does not support the COPY statement. I have tried enabling postgres compatibility mode by appending ';MODE=PostgreSQL' to my database url. This results in a error message stating 'File not found 'backup.sql'. I tried putting my dump in a file by that name and got the same message.
>>
>> I also tried sticking 'SET MODE PostgreSQL ;' at the top of my SQL dump file. This had no effect the script still abended with a syntax error on the COPY command.
>>
>> Where the best place to ask H2 questions? Is there an IRC room? A list serve?
>>
>> thanks!
>>
>> Eric
>>
>> +1 (917) 589-6579
>>
>>
>>
>

Re: Cayenne and H2 on the desktop

Posted by Michael Gentry <mg...@masslight.net>.
An embedded database is one that runs internally instead of requiring
a separate database server.  This makes it convenient for standalone
applications.

For the database connection itself, though, you'd want something like:

JDBC URL: jdbc:h2:~/mydb
Username: sa
Password: <blank>

As for PostgreSQL support in H2, I don't know anything about that.  Sorry.

mrg


On Tue, Oct 20, 2009 at 8:00 PM, Eric Lazarus <er...@yahoo.com> wrote:
> Folks
>
> Thanks for you folks direction on using H2 as our database but we are a bit stuck on how to do it. We are moving toward using Cayenne 3.0M6 and H2 for the desktop version of an application that should be as idiot proof as possible. We want for the end user to not have to understand that there is a database there at all.
>
> Any suggestions about how we should configure things? For example, should we configure H2 to run embedded if we don't want the end user to have to be aware of it? How DO we configure it that way? What should we be reading to figure out how to do that? I am not even sure we understand what it means to run "embeded." Does that mean that that database is in the same VM? That we don't go via JDBC at all?
>
> Also, we are trying to load a postgres dump into H2 and am failing because H2 does not support the COPY statement. I have tried enabling postgres compatibility mode by appending ';MODE=PostgreSQL' to my database url. This results in a error message stating 'File not found 'backup.sql'. I tried putting my dump in a file by that name and got the same message.
>
> I also tried sticking 'SET MODE PostgreSQL ;' at the top of my SQL dump file. This had no effect the script still abended with a syntax error on the COPY command.
>
> Where the best place to ask H2 questions? Is there an IRC room? A list serve?
>
> thanks!
>
> Eric
>
> +1 (917) 589-6579
>
>
>

Re: Cayenne and H2 on the desktop

Posted by Michael Gentry <mg...@masslight.net>.
On Tue, Oct 20, 2009 at 11:56 PM, Eric Lazarus <er...@yahoo.com> wrote:
> Thanks, Folks!
>
> What 'adapter' do I use for H2 in cayenne.xml? What 'adapter' do I use for H2 in cayenne.xml? I imagine it will be something like cayenne.dba.H2.H2Adapter?

Cayenne should auto-guess the adapter.  I should've mentioned that you
should plug the driver into Cayenne Modeler, too.

JDBC Driver: org.h2.Driver

And do what Mike suggested and leave the username out.  I didn't know
that would work and it is probably better for your situation.

> About the meaning of 'embedded': I think that the 2nd option has a
> server process running tcp on some port number in the 9000's. Does this
> count as an 'embedded' database? I assume not.

Maybe if you wanted to get pedantic, you could argue that the DB is
still embedded in the application, but when it runs as a server, I
really don't consider that embedded.

> Also, what happens in the
> first case if the user opens two instances of the program on his
> desktop. Does not each instance access the same files ? What kind of
> locking is implemented in that case?

You can tell H2 to not lock the database, but you don't want to do
that.  According to the docs: "Please note that this is unsafe as
another process is able to open the same database, possibly leading to
data corruption."  I'm guessing you'd prefer using a SOCKET lock:

http://www.h2database.com/html/features.html#database_file_locking

> Thanks!
>
> Eric

Welcome!

mrg

Re: Cayenne and H2 on the desktop

Posted by John Armstrong <si...@gmail.com>.
I implemented a DataSourceFactory to obtain this same functionality.
specifically around having a single executable JAR and derby not
finding its schema creation file. The DSF lets the system auto-detect
schema existence and use embedded ant to create it as required.

Your mileage may vary
John-

On Tue, Oct 20, 2009 at 5:10 PM, Mike Kienenberger <mk...@gmail.com> wrote:
> Do you want the database to be a single-user resource which is
> persisted between runs?
>
> If so, it should be as simple as using jdbc:h2:~/test/testdatabase as
> your jdbc url where "~/test/cistestdatabase" is the path to your
> database (it will be a directory).  Most likely, this is what you
> want.
>
> Using jdbc:h2:tcp://localhost/~/test/testdatabase will connect as a
> standard standalone database instance and assumes you started it
> standalone.   This is now multiuser.
>
> The list for technical questions is a google group.
>
> http://groups.google.com/group/h2-database
>
>
> On Tue, Oct 20, 2009 at 8:00 PM, Eric Lazarus <er...@yahoo.com> wrote:
>> Folks
>>
>> Thanks for you folks direction on using H2 as our database but we are a bit stuck on how to do it. We are moving toward using Cayenne 3.0M6 and H2 for the desktop version of an application that should be as idiot proof as possible. We want for the end user to not have to understand that there is a database there at all.
>>
>> Any suggestions about how we should configure things? For example, should we configure H2 to run embedded if we don't want the end user to have to be aware of it? How DO we configure it that way? What should we be reading to figure out how to do that? I am not even sure we understand what it means to run "embeded." Does that mean that that database is in the same VM? That we don't go via JDBC at all?
>>
>> Also, we are trying to load a postgres dump into H2 and am failing because H2 does not support the COPY statement. I have tried enabling postgres compatibility mode by appending ';MODE=PostgreSQL' to my database url. This results in a error message stating 'File not found 'backup.sql'. I tried putting my dump in a file by that name and got the same message.
>>
>> I also tried sticking 'SET MODE PostgreSQL ;' at the top of my SQL dump file. This had no effect the script still abended with a syntax error on the COPY command.
>>
>> Where the best place to ask H2 questions? Is there an IRC room? A list serve?
>>
>> thanks!
>>
>> Eric
>>
>> +1 (917) 589-6579
>>
>>
>>
>

Re: Updating Cayenne Advice 1.x => 3.0: createAndRegisterNewObject is deprecated...

Posted by Kevin Menard <ni...@gmail.com>.
Hi Eric,

It's been a while since I've upgraded from 1.x.  Cayenne 2.x should be
API compatible with 1.2, save for the new apache package names.  The
changes from 2.x to 3.x were mostly backward compatible.  If you
wanted to, you could upgrade in two steps, using 2.x to make sure you
got all the object references correct.

newObject should do what you need now.  The data object will be
automatically registered with the ObjectContext (note that this now
the new interface for DataContext and CayenneContext).  You can
associate unregistered objects with registered ones and they'll be
automatically registered with the same context as well.

The really big change you need to be aware of is that Cayenne 3 is
Java 5+ only.  So, if you need to run on an older JVM you should stick
with 1.2/2.x.

-- 
Kevin



On Wed, Oct 21, 2009 at 8:07 AM, Eric Lazarus <er...@yahoo.com> wrote:
> We have been using 1.x happily for years and now finally have a reason to upgrade: our need for embedded database (e.g., H2) support. Seems like createAndRegisterNewObject is deprecated. I assume we are supposed to use one or another version of newObject() instead. Is that right? What else should we do differently?
>
> What OTHER advice do you have for someone finally getting around to upgrading?
>
> Thanks!
>
> Eric
>
>
>
>

Updating Cayenne Advice 1.x => 3.0: createAndRegisterNewObject is deprecated...

Posted by Eric Lazarus <er...@yahoo.com>.
We have been using 1.x happily for years and now finally have a reason to upgrade: our need for embedded database (e.g., H2) support. Seems like createAndRegisterNewObject is deprecated. I assume we are supposed to use one or another version of newObject() instead. Is that right? What else should we do differently? 

What OTHER advice do you have for someone finally getting around to upgrading? 

Thanks! 

Eric



      

Re: Cayenne and H2 on the desktop

Posted by Aristedes Maniatis <ar...@maniatis.org>.
On 21/10/09 2:56 PM, Eric Lazarus wrote:
> About the meaning of 'embedded': I think that the 2nd option has a
> server process running tcp on some port number in the 9000's. Does this
> count as an 'embedded' database? I assume not.
>
> Also, what happens in the
> first case if the user opens two instances of the program on his
> desktop. Does not each instance access the same files ? What kind of
> locking is implemented in that case?

I don't use H2, but for Derby:

* you can 'embed' the Derby jar within your own application jar or you can run it standalone
* if you embed it or if it runs standalone, you can have it open a TCP socket and communicate with it just as if it was a separate application. Other apps can also connect.
* if you embed it, you can also use a different JDBC connector to connect directly without a TCP socket. That might be more secure, but it doesn't make anything simpler (or faster).
* whatever you do, you cannot have two database engines (standalone or embedded) using the same files on disk. I'd guess that holds true for any database in existence today.

Ari

-- 

-------------------------->
Aristedes Maniatis
GPG fingerprint CBFB 84B4 738D 4E87 5E5C  5EFA EF6A 7D2E 3E49 102A

Re: Cayenne and H2 on the desktop

Posted by Eric Lazarus <er...@yahoo.com>.
Thanks, Folks!

What 'adapter' do I use for H2 in cayenne.xml? What 'adapter' do I use for H2 in cayenne.xml? I imagine it will be something like cayenne.dba.H2.H2Adapter?

About the meaning of 'embedded': I think that the 2nd option has a
server process running tcp on some port number in the 9000's. Does this
count as an 'embedded' database? I assume not.

Also, what happens in the
first case if the user opens two instances of the program on his
desktop. Does not each instance access the same files ? What kind of
locking is implemented in that case?

Thanks! 

Eric



--- On Tue, 10/20/09, Mike Kienenberger <mk...@gmail.com> wrote:

From: Mike Kienenberger <mk...@gmail.com>
Subject: Re: Cayenne and H2 on the desktop
To: user@cayenne.apache.org
Date: Tuesday, October 20, 2009, 8:10 PM

Do you want the database to be a single-user resource which is
persisted between runs?

If so, it should be as simple as using jdbc:h2:~/test/testdatabase as
your jdbc url where "~/test/cistestdatabase" is the path to your
database (it will be a directory).  Most likely, this is what you
want.

Using jdbc:h2:tcp://localhost/~/test/testdatabase will connect as a
standard standalone database instance and assumes you started it
standalone.   This is now multiuser.

The list for technical questions is a google group.

http://groups.google.com/group/h2-database


On Tue, Oct 20, 2009 at 8:00 PM, Eric Lazarus <er...@yahoo.com> wrote:
> Folks
>
> Thanks for you folks direction on using H2 as our database but we are a bit stuck on how to do it. We are moving toward using Cayenne 3.0M6 and H2 for the desktop version of an application that should be as idiot proof as possible. We want for the end user to not have to understand that there is a database there at all.
>
> Any suggestions about how we should configure things? For example, should we configure H2 to run embedded if we don't want the end user to have to be aware of it? How DO we configure it that way? What should we be reading to figure out how to do that? I am not even sure we understand what it means to run "embeded." Does that mean that that database is in the same VM? That we don't go via JDBC at all?
>
> Also, we are trying to load a postgres dump into H2 and am failing because H2 does not support the COPY statement. I have tried enabling postgres compatibility mode by appending ';MODE=PostgreSQL' to my database url. This results in a error message stating 'File not found 'backup.sql'. I tried putting my dump in a file by that name and got the same message.
>
> I also tried sticking 'SET MODE PostgreSQL ;' at the top of my SQL dump file. This had no effect the script still abended with a syntax error on the COPY command.
>
> Where the best place to ask H2 questions? Is there an IRC room? A list serve?
>
> thanks!
>
> Eric
>
> +1 (917) 589-6579
>
>
>



      

Re: Cayenne and H2 on the desktop

Posted by Mike Kienenberger <mk...@gmail.com>.
Do you want the database to be a single-user resource which is
persisted between runs?

If so, it should be as simple as using jdbc:h2:~/test/testdatabase as
your jdbc url where "~/test/cistestdatabase" is the path to your
database (it will be a directory).  Most likely, this is what you
want.

Using jdbc:h2:tcp://localhost/~/test/testdatabase will connect as a
standard standalone database instance and assumes you started it
standalone.   This is now multiuser.

The list for technical questions is a google group.

http://groups.google.com/group/h2-database


On Tue, Oct 20, 2009 at 8:00 PM, Eric Lazarus <er...@yahoo.com> wrote:
> Folks
>
> Thanks for you folks direction on using H2 as our database but we are a bit stuck on how to do it. We are moving toward using Cayenne 3.0M6 and H2 for the desktop version of an application that should be as idiot proof as possible. We want for the end user to not have to understand that there is a database there at all.
>
> Any suggestions about how we should configure things? For example, should we configure H2 to run embedded if we don't want the end user to have to be aware of it? How DO we configure it that way? What should we be reading to figure out how to do that? I am not even sure we understand what it means to run "embeded." Does that mean that that database is in the same VM? That we don't go via JDBC at all?
>
> Also, we are trying to load a postgres dump into H2 and am failing because H2 does not support the COPY statement. I have tried enabling postgres compatibility mode by appending ';MODE=PostgreSQL' to my database url. This results in a error message stating 'File not found 'backup.sql'. I tried putting my dump in a file by that name and got the same message.
>
> I also tried sticking 'SET MODE PostgreSQL ;' at the top of my SQL dump file. This had no effect the script still abended with a syntax error on the COPY command.
>
> Where the best place to ask H2 questions? Is there an IRC room? A list serve?
>
> thanks!
>
> Eric
>
> +1 (917) 589-6579
>
>
>