In a Derby database, how are "username" and "table owner" related, and what is a simple way to set them?

StackOverflow https://stackoverflow.com/questions/14928740

Domanda

I am using Derby to study Hibernate; I used to have it as an embedded database, but my ant jobs for filling it with data have trouble with that, so I'm switching to the network version.

Besides my Java/Hibernate program, I access the database with a Squirrel client. I just want a setup that is as simple as possible; I don't need even normal security, encryption, etc.

I've been using Squirrel to create the database, and a sql script to create tables. Then I run an ant job out of eclipse that puts data in the tables. The ant scripts would load one record when all I had was an embedded database, then say that the database was 'already open'; I switched to network server mode to allow the ant scripts to do more than one record.

The squirrel client refuses to connect unless there is a non-0-length username and password, so I put in admin/admin.

When I do this, it seems the database tables are organized under the username somehow. The 'Objects' window in squirrel shows the database name, ADMIN and some other things under that, TABLE and some other things under ADMIN, and then the tables I created under ADMIN. ADMIN does not appear in the Sql script, only in the username I use to create and log into the database, so I assume the tables are under ADMIN because that's my username; I don't know where else it would come from.

Whether I put "username=admin;password=admin" on the URL in my hibernate configuration or not, it says the (first) table I'm trying to add to doesn't exist.

So can someone please tell me what I have to do to have Squirrel and Java/Hibernate access the same tables as each other in a Derby database? I think a rudimentary understanding of the terms above -- username, schema, qualifiedName, and simpleName, as they are used by Squirrel and/or Derby, might do the trick.

Here's one of the table creations:

create table AdUser
(   id bigint generated by default as identity (start with 1),
    name varchar(255),
    password varchar(255),
    primary key (id),
    unique(name)
);

and here's the hibernate config file:

<property name="hibernate.connection.url"> jdbc:derby://localhost:1527/C:/Users/rcook/workspaceGalileoLaptop/BHChap3/BegHibernateDB;username=admin;password=admin</property>
<property name="hibernate.connection.driver_class"> org.apache.derby.jdbc.ClientDriver40 </property>
<!--  <property name="hibernate.connection.username">sa</property>  -->
<!--  <property name="hibernate.connection.password"></property> -->
<property name="hibernate.dialect">   org.hibernate.dialect.DerbyDialect  </property>

<property name="hibernate.connection.pool_size">0</property>
<property name="hibernate.show_sql">false</property>

Let me repeat; this worked for one record in an embedded database, so I'm confident that the code for connecting, creating the mapped objects, committing, etc., all works; but I'm convinced I'm doing something wrong with the logins from the two access methods.

È stato utile?

Soluzione

There is indeed an intermediate level of table organization inside each database called the "schema"; you can read more about Derby's schema implementation here: http://db.apache.org/derby/docs/10.9/ref/rrefschemaname.html

Note that the schema name defaults to your user name, but you can always explicitly specify the schema name in your queries:

select * from admin.aduser;

accesses a different table than does

select * from rcook.aduser;
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top