1

I wanted to know what is the way to mention database schema name in persistence.xml file.

Here is my file.

<?xml version="1.0" encoding="UTF-8" ?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
             version="1.0">
    <persistence-unit name="ORDER"
                      transaction-type="RESOURCE_LOCAL">
        <provider>
        org.eclipse.persistence.jpa.PersistenceProvider
    </provider>
        <properties>
            <property name="javax.persistence.jdbc.driver"
                      value="oracle.jdbc.OracleDriver"/>
            <property name="javax.persistence.jdbc.url"
                      value="xyzurl"/>
            <property name="javax.persistence.jdbc.password" value="YYYYY"/>
            <property name="javax.persistence.jdbc.user" value="XXXX"/>
        </properties>
    </persistence-unit>
</persistence>

The schema name is testdta.

Any inputs will be helpful.

gtgaxiola
  • 9,241
  • 5
  • 42
  • 64
user2988851
  • 157
  • 2
  • 13
  • Can you tell a purpose of this ? Thanks – energizer Nov 11 '14 at 19:51
  • 1
    http://stackoverflow.com/questions/2737420/how-to-set-up-default-schema-name-in-jpa-configuration – Multisync Nov 11 '14 at 19:51
  • Databases are NOT called Schemas. – BatScream Nov 11 '14 at 19:56
  • @Kamran Amini Really?? – Multisync Nov 11 '14 at 19:57
  • @Multisync Sorry:) Schemas are schemas. Databases are databases. I had a bad dream! – Kamran Amini Nov 11 '14 at 20:09
  • @energizer:To query a SQL statement in java. – user2988851 Nov 11 '14 at 20:12
  • @user2988851 is this mandatory parameter? I do not use this and everything just works great. Any other reason to use this? Hibernate should take schema from specified datasource. I consider one reason for using schema name, when you have N different schemas and you want to swap it dynamically. Also you should specify hibernate dialect to give a hint for hibernate which database SQL language you are using. – energizer Nov 11 '14 at 20:24
  • @energizer: Java class with the SQL statement is complaining about error near the table name (I guess its expecting the schema name ? Bcoz thats how I run it in SQL workbench). – user2988851 Nov 11 '14 at 20:31
  • The third answer down in Multisync's response gives you the answer in a non-provider specific JPA way, or you can see the answer here: http://nagareddyss.wordpress.com/2013/03/13/database-schema-name-configuration-in-eclipselink-jpa/ If you are looking for a dynamic solution, you need to get into provider specific options and properties. – Chris Nov 12 '14 at 02:20

2 Answers2

1

Specify your schema name in against the javax.persistence.jdbc.user property.

<property name="javax.persistence.jdbc.user" value="testdta"/>
<property name="javax.persistence.jdbc.password" value="schema password"/>

In case you are not aware, specify the datasource URI here:

<property name="javax.jdbc.url" value="jdbc:oracle:thin:@localhost:1521:service"/>
BatScream
  • 19,260
  • 4
  • 52
  • 68
0

Have a look at this link. This page explains how you can create persistence.xml for an Oracle database.

https://docs.oracle.com/cd/E16439_01/doc.1013/e13981/cfgdepds005.htm

Here is an example for toplink.jdbc.user property: (It is in TopLink of course!)

<properties>
    <property name="toplink.logging.level" value="INFO"/>
    <property name="toplink.jdbc.driver" value="oracle.jdbc.OracleDriver"/>
    <property name="toplink.jdbc.url" value="jdbc:oracle:thin:@myhost:l521:MYSID"/>
    <property name="toplink.jdbc.password" value="tiger"/>
    <property name="toplink.jdbc.user" value="scott"/>
</properties>

Here, scott is the schema used for connecting to database.

Kamran Amini
  • 1,062
  • 8
  • 14