My application uses two schema and two persistence units.
I need that one Business Object mapped on the first schema/PU can read (and only read) data from a table mapped in the second schema/PU.
So I created a class mapped to the "foreign" table, with only the fields that I need with insertable and updatable set to false (so it should be read-only)
Code:
@Entity
@Table( name = "NETHZ_USER", schema = "IDMANLIGHT" )
@Inheritance( strategy = InheritanceType.JOINED )
public class CMNUser extends PersistentObject
{
private static final long serialVersionUID = CmnSerialVersionUID.getSerialVersionUID();
@Column( insertable = false, updatable = false )
private String firstName;
@Column( insertable = false, updatable = false )
private String lastName;
@Column( insertable = false, updatable = false )
private String nethzPrimaryUsername;
// Empty constructor need by Hibernate/Envers
public CMNUser()
{
super();
}
+ getters and setters
and put it in the persistence.xml under the first PU too.
The problem is that to create the DB I use the Hibernate Tools (hbm2ddl) and when it generates the script to create the tables for the first PU, it generates the create table idmanlight.nethz_user too. When then it tries to execute the script there is the error: "No rights for schema idmanlight" (which is legal).
The point is that hbm2ddl shouldn't generate the creation of the table (which already happens by the second PU).
Is there a way to avoid this?
I hope I explained the problem well enough to be understood...