users@glassfish.java.net

Database view with JPA for jdbc realm

From: <glassfish_at_javadesktop.org>
Date: Tue, 26 May 2009 00:11:42 PDT

Hi,

I have an application that uses form based security. The realm used is JDBC Realm. I have the entities User and Group for the JDBC realm. All database tables for the application are created when I deploy the application. For User and Group entities the tables users, groups and user_group is created. user_group is just a relation table to avoid redundancy by putting the username in the groups table.

However, glassfish jdbc realm implementation requires username to be in the same table as the group name. To solve this it is usually suggested to use a database view, that selects usernames from users table and group names from groups table.

But how can i get the container to create a database view, as it creates all the tables from the enteties? I tried the following:

In a constructor of a servlet that is loaded at startup, I tried to call an injected (with @EJB) EJB. The EJB has access to an entity manager and executes an SQL create view statement. But, the problem is that in the servlet constructor the EJB instance is still null. I can call the EJB from the doGet method, and it works, but I would like the view to be created at deploy time automatically.

My application is packaged in an EAR with one web module and two ejb modules.

BR,
Mattias
[Message sent by forum member 'nightzero' (nightzero)]

http://forums.java.net/jive/thread.jspa?messageID=347626