JPA entities to the database generation

Hi,
I am trying to create JPA entities in an EJB diagram and then automatically get the tables created in a database schema. I started by creating some entities from the Entity wizard, then added some fields, dragged them into the diagram and added some relationships.
With that done, I noticed that the tables in the offline database created by the wizard don't get updated with the new fields of the entities (they have only the id and version fields). And I couldn't figure out how to do so.
Then, I tried to use the option 'Synchronize with database -> Generate to' option in the context menu from the EJB diagram, but its options appear disabled for me.
Please, tell me if I am doing something wrong or expecting anything that the tool is not able to do for me.
Thanks for any help.

Disabling the bind variables produces the following:
INSERT INTO BIG_NUM (ID, NUM) VALUES (2, 9999999999999999.00)The database still joyfully contains a rounded number:
SQL> select * from big_num;
                 ID                   NUM
                  2  10000000000000000,00So, no, it's not an issue with the bind variables. I need to examine the JDBC driver but could you tell me how I can find out what Oracle JDBC driver is used by JPA? Or... is it some other JDBC driver (not Oracle, that is)?
Best regards,
Bisser
P.S. We use the following version of TopLink Essentials:
TopLink, version: Oracle TopLink Essentials - 2.1 (Build b60-fcs (11/17/2008))
Edited by: bisser on Jan 28, 2009 9:25 AM

Similar Messages

  • What is the best way to create fields at runtime in the database using JPA?

    We use Oracle ADF platform to build web applications and extend to webcenter portal application.
    The current expectation from Java developers team is to change our development approach/method, so that adding some fields in the application should not required any development effort. In other words, when you want to add a data field (at least no relation to any field) in some form, it should be enough to save some metadata of the field to the database along with execution of related job/commands in the application. Additionally, we need to render the view dynamically according to added fields.
    Essentially, I think that such an expectation is not suited for the Java world, but if it could be possible or if someone has prior experience to do this, I would want to use it. We don't want to be interact directly with the database using native SQL through JDBC, as that would mean going out of the ADF framework.
    Suppose that, we define the metadatas of custom field(s), for example its type(string, number, combobox etc)length, isunique, mandatory... And then we run the execute command of this field definition to create on database and map to related entity object from now on. I assume that might be possible to add entity class as property belonged to class. Anymore when rendering the page, new custom field must be shown in form view if even there is no deployment process...
    There is Extensible Entity in EclipseLink. Has anybody got sample project about used eclipselink extensible entities? I could not find enough detailed docs unfortunatelly
    http://wiki.eclipse.org/EclipseLink/UserGuide/JPA/Advanced_JPA_Development/Extensible_Entities#EclipseLink.2FUserGuide.2FJPA.2FAdvanced_JPA_Development.2FExternal_Mappings
    http://wiki.eclipse.org/EclipseLink/Examples/JPA/Dynamic#Usage_Examples
    http://flex.winfxpro.info/download/?noderef=workspace://SpacesStore/af69ebfb-6d9f-4a03-8244-c56100d16deb

    In the persistence.xml specify the property
    <property name="eclipselink.ddl-generation" value="create-tables"/>
    But, a JPA implementation is not required to create tables according to the EJB 3 JPA specification. The Hibernate persistence provider does, the EclipseLink doesn't.
    <provider>org.hibernate.ejb.HibernatePeristence</provider>

  • [JPA] Saving big numbers to the database

    Hi,
    I have a JPA problem that I cannot solve. I try to save a large number to the database and JPA performs some strange rounding. For example, saving the number 9999999999999999.00 produces the following number in the database: 10000000000000000.00.
    Actually, I'm not sure if it's JPA or the Oracle JDBC driver, but somebody rounds the number. That's bad!
    Here's how to reproduce the issue:
    1. Database:
    create table big_num
    (id  number(18),
      num number(19,2));
    alter table big_num
      add constraint big_num_pk primary key (id);
    create sequence big_num_seq
      start with 1
      nocache;2. Entity:
    @Entity
    @Table(name="BIG_NUM")
    @SequenceGenerator(name="bigNumSeq", sequenceName="BIG_NUM_SEQ", allocationSize=1)
    public class BigNum {
         @Id
         @Column(name="ID", nullable=false)
         @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="bigNumSeq")
         private Long id;
         @Column(name="NUM")
         private BigDecimal num;
         public Long getId() {
              return id;
         public void setId(Long id) {
              this.id = id;
         public BigDecimal getNum() {
              return num;
         public void setNum(BigDecimal num) {
              this.num = num;
    }3. Code that causes the problem:
         BigNum bn = new BigNum();
         bn.setNum(new BigDecimal("9999999999999999.00"));
         em.getTransaction().begin();
         em.persist(bn);
         em.getTransaction().commit();So, the INSERT statement that iss generated to the database is:
    INSERT INTO BIG_NUM (ID, NUM) VALUES (?, ?)
    bind => [1, 9999999999999999.00]However, the database contains the following:
    SQL> select * from big_num;
                     ID                   NUM
                      1  10000000000000000,00Can somebody tell me if it's possible to save big numbers accurately into the database? If yes, then how?
    Best regards,
    Bisser

    Disabling the bind variables produces the following:
    INSERT INTO BIG_NUM (ID, NUM) VALUES (2, 9999999999999999.00)The database still joyfully contains a rounded number:
    SQL> select * from big_num;
                     ID                   NUM
                      2  10000000000000000,00So, no, it's not an issue with the bind variables. I need to examine the JDBC driver but could you tell me how I can find out what Oracle JDBC driver is used by JPA? Or... is it some other JDBC driver (not Oracle, that is)?
    Best regards,
    Bisser
    P.S. We use the following version of TopLink Essentials:
    TopLink, version: Oracle TopLink Essentials - 2.1 (Build b60-fcs (11/17/2008))
    Edited by: bisser on Jan 28, 2009 9:25 AM

  • JDev generates incomplete Tables from JPA entities

    I've got some JPA entities and I'm trying to generate the DB schema from them in Jdeveloper.
    All tables are only generated with the Id (Primary Key) and not any additional fields/constraints I've defined in the Entity classes.
    Any ideas what I should be looking at?
    JDev 11.1.1.3 connecting to Oracle 10g XE
    Edited by: new_to_webcenter on 21-Jan-2011 03:20

    @Shay,
    In a new JPA app, I've created
    New Business Tier > EJB > Entity
    Choose Persistence Unit and OFfline DB , Choose No Inheritance
    Ticked on "Create Offline Table"
    Include @Id field without a Sequencer
    In the generated Entity class, I've added a new private field Name with setter/getter.
    I've added these via the Structure > EJB > Add new field > generate accessors.
    I've also specified @Column for the private field Name .
    Next in the offline DB source, I right-click the Table > Generate to Connection > and go through the steps , choosing CREATE table.
    In the created table as well as the generated SQL script, the Name column does not appear.
    It creates a table in the DB with only the ID column.
    Edit: I've checked again - if i click on the offline db source > table > columns - even there it only shows ID and no NAME column.
    Any ideas - i'm definitely missing a step?
    In persistence.xml I've specified
    <property name="eclipselink.target-server" value="WebLogic_10"/>
    <property name="eclipselink.ddl-generation.output-mode"
                        value="database" />
    @dvohra16 : Nope I dont need the sequencer at present.
    Edited by: new_to_webcenter on 21-Jan-2011 22:37
    Edited by: new_to_webcenter on 21-Jan-2011 22:58

  • EJB 3.0 - JSF APPLICATION: DATA DOES NOT PERSIST TO THE DATABASE

    Hi,
    I am developing a JSF - EJB application and the data that I send from JSP Page through JSF Managed Bean --> Session Bean --> Java Persistence does not persist in database.
    Here is my scenario ( Iam using JDeveloper IDE to create this application) -
    SCENARIO START
    The scenario consists of two web pages, one enlisting all the users stored in the database, the other contains a form for adding a user
    1.) INDEX.JSP
    2.) ADDUSER.JSP
    Step 1: Create the USERS Table in database
    CREATE TABLE users
    user_id serial,
    username varchar(255) NOT NULL,
    first_name varchar(255),
    last_name varchar(255),
    password char(64) NOT NULL,
    CONSTRAINT pk_users PRIMARY KEY (user_id)
    Step 2: Add Database Connection To JDeveloper
    Go to Database Connection Navigator and create a New Database Connection using the Wizard
    Step 3: Create a New Application in JDeveloper and select JSF, EJB from Application Template
    Step 4: ENTITY BEAN - In the EJB Node Right Click and Select EJB à New Entites from Table (JPA/EJB3.0)
    Use The Wizard and create Entity Bean from Users Table which creates an Entity Bea POJO file as follows –
    User.java -
    package lux.domain;
    import java.io.Serializable;
    import javax.persistence.Column;
    import javax.persistence.Entity;
    import javax.persistence.GeneratedValue;
    import javax.persistence.GenerationType;
    import javax.persistence.Id;
    import javax.persistence.NamedQuery;
    import javax.persistence.SequenceGenerator;
    import javax.persistence.Table;
    @Entity
    @NamedQuery(name = "User.findAll", query = "select o from User o")
    @Table(name = "USERS")
    public class User implements Serializable {
    @Column(name="FIRST_NAME")
    private String firstName;
    @Column(name="LAST_NAME")
    private String lastName;
    @Column(nullable = false)
    private String password;
    @Column(nullable = false)
    private String username;
    @Id
    @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="users_seq_generator")
    @SequenceGenerator(name="users_seq_generator", sequenceName="users_user_id_seq")
    @Column(name="USER_ID", nullable = false)
    private Long userId;
    public User() {
    public String getFirstName() {
    return firstName;
    public void setFirstName(String firstName) {
    this.firstName = firstName;
    public String getLastName() {
    return lastName;
    public void setLastName(String lastName) {
    this.lastName = lastName;
    public String getPassword() {
    return password;
    public void setPassword(String password) {
    this.password = password;
    public String getUsername() {
    return username;
    public void setUsername(String username) {
    this.username = username;
    public Long getUserId() {
    return userId;
    public void setUserId(Long userId) {
    this.userId = userId;
    Step 5: STATELESS SESSION BEAN - In the EJB Node Right Click and Select EJB à New Entites from Table (JPA/EJB3.0)
    Again Right Click on Model and create Session Bean from Wizard which creates two files –
    UserDAOBean.java – Stateless Session Bean
    UserDAO.java – Local Interface
    package lux.facade;
    import java.security.MessageDigest;
    import java.security.NoSuchAlgorithmException;
    import java.util.List;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    import javax.ejb.Stateless;
    import javax.persistence.EntityManager;
    import javax.persistence.PersistenceContext;
    import javax.persistence.Query;
    import lux.domain.User;
    @Stateless(name="UserDAO")
    public class UserDAOBean implements UserDAO {
    @PersistenceContext(unitName="Model")
    private EntityManager em;
    public UserDAOBean() {
    public User getUser(int UserId) {
    User u = new User();
    u = em.find(User.class, UserId);
    return u;
    public List<User> getAllUsers() {
    Query q = em.createQuery("SELECT u FROM User u");
    List<User> users = q.getResultList();
    return users;
    public void createUser(User u) {
    String hashedPw = hashPassword(u.getPassword());
    u.setPassword(hashedPw);
    em.persist(u);
    public void updateUser(User u) {
    String hashedPw = hashPassword(u.getPassword());
    u.setPassword(hashedPw);
    em.merge(u);
    public void deleteUser(User u) {
    em.remove(u);
    private String hashPassword(String password) {
    StringBuilder sb = new StringBuilder();
    try {
    MessageDigest messageDigest = MessageDigest.getInstance("SHA");
    byte[] bs;
    bs = messageDigest.digest(password.getBytes());
    for (int i = 0; i < bs.length; i++) {
    String hexVal = Integer.toHexString(0xFF & bs);
    if (hexVal.length() == 1) {
    sb.append("0");
    sb.append(hexVal);
    } catch (NoSuchAlgorithmException ex) {
    Logger.getLogger(UserDAOBean.class.getName()).log(Level.SEVERE, null, ex);
    return sb.toString();
    Step 6: Create a Deployment file in the Model and Deploy this to a JAR file
    Step 7: Now Right Click on View/Controller Node and create a Java File –
    UserController.java -
    package lux.controllers;
    import javax.ejb.EJB;
    import javax.faces.model.DataModel;
    import javax.faces.model.ListDataModel;
    import lux.domain.User;
    import lux.facade.UserDAO;
    public class UserController {
    @EJB UserDAO userDao;
    private User user;
    private DataModel model;
    public String createUser() {
    this.user = new User();
    return "create_new_user";
    public String saveUser() {
    String r = "success";
    try {
    userDao.createUser(user);
    } catch (Exception e) {
    e.printStackTrace();
    r = "failed";
    return r;
    public DataModel getUsers() {
    model = new ListDataModel(userDao.getAllUsers());
    return model;
    public User getUser() {
    return user;
    public void setUser(User user) {
    this.user = user;
    Step 8: Configure page flow in faces-config.xml
    1. Create the JSP file adduser.jsp by right-clicking View-Controller
    node and selecting New > JSP. Use the wizard to create JSF – JSP Page, fill in
    File Name adduser.jsp, click Finish. -
    <%@page contentType="text/html"%>
    <%@page pageEncoding="UTF-8"%>
    <%@taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
    <%@taglib prefix="h" uri="http://java.sun.com/jsf/html"%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>New user</title>
    </head>
    <body>
    <f:view>
    <h:form>
    <h:messages/>
    <h:panelGrid columns="2">
    <h:outputText value="Username"/>
    <h:inputText
    id="Username"
    value="#{user.user.username}"
    required="true"/>
    <h:outputText value="First name"/>
    <h:inputText
    id="FirstName"
    value="#{user.user.firstName}" />
    <h:outputText value="Last name"/>
    <h:inputText
    id="LastName"
    value="#{user.user.lastName}" />
    <h:outputText value="Password" />
    <h:inputSecret
    id="Password"
    value="#{user.user.password}"
    required="true" />
    <h:panelGroup/>
    <h:commandButton
    action="#{user.saveUser}"
    value="Save"/>
    </h:panelGrid>
    </h:form>
    </f:view>
    </body>
    </html>
    2. Repeat the previous step for another JSP file failed.jsp.
    3. On failed.jsp add the string
    Save failed
    Next we configure the page flow.
    1. Open faces-config.xml.
    2. Create index.jsp -
    <%@page contentType="text/html"%>
    <%@page pageEncoding="UTF-8"%>
    <%@taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
    <%@taglib prefix="h" uri="http://java.sun.com/jsf/html"%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>User Listing</title>
    </head>
    <body>
    <f:view>
    <h:form>
    <h:outputText value="User Listing"/>
    <h:commandLink action="#{user.createUser}" value="Create a user"/>
    <h:dataTable value="#{user.user}"
    var="dataTableItem" border="1" cellpadding="2" cellspacing="2">
    <h:column>
    <f:facet name="header">
    <h:outputText value="Username"/>
    </f:facet>
    <h:outputText value="#{dataTableItem.username}" />
    </h:column>
    <h:column>
    <f:facet name="header">
    <h:outputText value="First name"/>
    </f:facet>
    <h:outputText value="#{dataTableItem.firstName}" />
    </h:column>
    <h:column>
    <f:facet name="header">
    <h:outputText value="Last name"/>
    </f:facet>
    <h:outputText value="#{dataTableItem.lastName}" />
    </h:column>
    </h:dataTable>
    </h:form>
    </f:view>
    </body>
    </html>
    3. Drag an arrow from index.jsp to adduser.jsp and replace the arrow’s label to create_new_user.
    4. Repeat the previous step for failed, by dragging and arrow from adduser.jsp to failed.jsp renaming the label to f
    ailed
    5. Finally repeat the step for adduser.jsp, by dragging from adduser.jsp to index.jsp renaming the label to success.
    This creates the following faces-config.xml file –
    <?xml version='1.0' encoding='UTF-8'?>
    <faces-config>
    <managed-bean>
    <managed-bean-name>user</managed-bean-name>
    <managed-bean-class>lux.controllers.UserController</managed-bean-class>
    <managed-bean-scope>session</managed-bean-scope>
    <managed-property>
    <property-name>username</property-name>
    <value>#{username}</value>
    </managed-property>
    <managed-property>
    <property-name>firstName</property-name>
    <value>#{firstName}</value>
    </managed-property>
    <managed-property>
    <property-name>lastName</property-name>
    <value>#{lastName}</value>
    </managed-property>
    <managed-property>
    <property-name>password</property-name>
    <value>#{password}</value>
    </managed-property>
    </managed-bean>
    <navigation-rule>
    <from-view-id>/index.jsp</from-view-id>
    <navigation-case>
    <from-outcome>create_new_user</from-outcome>
    <to-view-id>/adduser.jsp</to-view-id>
    </navigation-case>
    </navigation-rule>
    <navigation-rule>
    <from-view-id>/adduser.jsp</from-view-id>
    <navigation-case>
    <from-outcome>failed</from-outcome>
    <to-view-id>/failed.jsp</to-view-id>
    </navigation-case>
    <navigation-case>
    <from-outcome>success</from-outcome>
    <to-view-id>/index.jsp</to-view-id>
    </navigation-case>
    </navigation-rule>
    </faces-config>
    Step 9: Create a Deployment file in the View-Controller and Deploy this to a WAR file
    Step 10: Create a Deployment file in the View-Controller and create an EAR file and add Model’s JAR and View-Controller’s
    WAR files to it.
    Step 11: Run the JSP Files
    SCENARIO END
    Now, When I execute Index.jsp, it does not list values from database and when I click on Create User link, it takes me to adduser.jsp page. When I fill values in this page and click Save button, it takes me to Save Failed page and data does not persist to the database.
    WHAT IS WRONG OUT HERE ???

    If you set a breakpoint in your createUser method - does this code get executed?
    We have a couple of tutorials that might show you how to do this.
    EJB/JSF with ADF-binding tutorial:
    http://www.oracle.com/technology/obe/obe1013jdev/10131/ejb_and_jpa/master-detail_pagewith_ejb.htm
    EJB/JSF without ADF binding:
    http://www.oracle.com/technology/obe/JavaEE_tutorial_10131/index.htm

  • JSF - EJB 3.0 Application - Data does not persist to the database

    Hi,
    I am developing a JSF - EJB application and the data that I send from JSP Page through JSF Managed Bean --> Session Bean --> Java Persistence does not persist in database.
    Here is my scenario ( Iam using JDeveloper IDE to create this application) -
    ------------------------------------------------------- SCENARIO START
    The scenario consists of two web pages, one enlisting all the users stored in the database, the other contains a form for adding a user
    1.) INDEX.JSP
    2.) ADDUSER.JSP
    Step 1: Create the USERS Table in database
    CREATE TABLE users
    user_id serial,
    username varchar(255) NOT NULL,
    first_name varchar(255),
    last_name varchar(255),
    password char(64) NOT NULL,
    CONSTRAINT pk_users PRIMARY KEY (user_id)
    Step 2: Add Database Connection To JDeveloper
    Go to Database Connection Navigator and create a New Database Connection using the Wizard
    Step 3: Create a New Application in JDeveloper and select JSF, EJB from Application Template
    Step 4: ENTITY BEAN - In the EJB Node Right Click and Select EJB � New Entites from Table (JPA/EJB3.0)
    Use The Wizard and create Entity Bean from Users Table which creates an Entity Bea POJO file as follows �
    User.java -
    package lux.domain;
    import java.io.Serializable;
    import javax.persistence.Column;
    import javax.persistence.Entity;
    import javax.persistence.GeneratedValue;
    import javax.persistence.GenerationType;
    import javax.persistence.Id;
    import javax.persistence.NamedQuery;
    import javax.persistence.SequenceGenerator;
    import javax.persistence.Table;
    @Entity
    @NamedQuery(name = "User.findAll", query = "select o from User o")
    @Table(name = "USERS")
    public class User implements Serializable {
    @Column(name="FIRST_NAME")
    private String firstName;
    @Column(name="LAST_NAME")
    private String lastName;
    @Column(nullable = false)
    private String password;
    @Column(nullable = false)
    private String username;
    @Id
    @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="users_seq_generator")
    @SequenceGenerator(name="users_seq_generator", sequenceName="users_user_id_seq")
    @Column(name="USER_ID", nullable = false)
    private Long userId;
    public User() {
    public String getFirstName() {
    return firstName;
    public void setFirstName(String firstName) {
    this.firstName = firstName;
    public String getLastName() {
    return lastName;
    public void setLastName(String lastName) {
    this.lastName = lastName;
    public String getPassword() {
    return password;
    public void setPassword(String password) {
    this.password = password;
    public String getUsername() {
    return username;
    public void setUsername(String username) {
    this.username = username;
    public Long getUserId() {
    return userId;
    public void setUserId(Long userId) {
    this.userId = userId;
    Step 5: STATELESS SESSION BEAN - In the EJB Node Right Click and Select EJB � New Entites from Table (JPA/EJB3.0)
    Again Right Click on Model and create Session Bean from Wizard which creates two files �
    UserDAOBean.java � Stateless Session Bean
    UserDAO.java � Local Interface
    package lux.facade;
    import java.security.MessageDigest;
    import java.security.NoSuchAlgorithmException;
    import java.util.List;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    import javax.ejb.Stateless;
    import javax.persistence.EntityManager;
    import javax.persistence.PersistenceContext;
    import javax.persistence.Query;
    import lux.domain.User;
    @Stateless(name="UserDAO")
    public class UserDAOBean implements UserDAO {
    @PersistenceContext(unitName="Model")
    private EntityManager em;
    public UserDAOBean() {
    public User getUser(int UserId) {
    User u = new User();
    u = em.find(User.class, UserId);
    return u;
    public List<User> getAllUsers() {
    Query q = em.createQuery("SELECT u FROM User u");
    List<User> users = q.getResultList();
    return users;
    public void createUser(User u) {
    String hashedPw = hashPassword(u.getPassword());
    u.setPassword(hashedPw);
    em.persist(u);
    public void updateUser(User u) {
    String hashedPw = hashPassword(u.getPassword());
    u.setPassword(hashedPw);
    em.merge(u);
    public void deleteUser(User u) {
    em.remove(u);
    private String hashPassword(String password) {
    StringBuilder sb = new StringBuilder();
    try {
    MessageDigest messageDigest = MessageDigest.getInstance("SHA");
    byte[] bs;
    bs = messageDigest.digest(password.getBytes());
    for (int i = 0; i < bs.length; i++) {
    String hexVal = Integer.toHexString(0xFF & bs);
    if (hexVal.length() == 1) {
    sb.append("0");
    sb.append(hexVal);
    } catch (NoSuchAlgorithmException ex) {
    Logger.getLogger(UserDAOBean.class.getName()).log(Level.SEVERE, null, ex);
    return sb.toString();
    Step 6: Create a Deployment file in the Model and Deploy this to a JAR file
    Step 7: Now Right Click on View/Controller Node and create a Java File �
    UserController.java -
    package lux.controllers;
    import javax.ejb.EJB;
    import javax.faces.model.DataModel;
    import javax.faces.model.ListDataModel;
    import lux.domain.User;
    import lux.facade.UserDAO;
    public class UserController {
    @EJB UserDAO userDao;
    private User user;
    private DataModel model;
    public String createUser() {
    this.user = new User();
    return "create_new_user";
    public String saveUser() {
    String r = "success";
    try {
    userDao.createUser(user);
    } catch (Exception e) {
    e.printStackTrace();
    r = "failed";
    return r;
    public DataModel getUsers() {
    model = new ListDataModel(userDao.getAllUsers());
    return model;
    public User getUser() {
    return user;
    public void setUser(User user) {
    this.user = user;
    Step 8: Configure page flow in faces-config.xml
    1. Create the JSP file adduser.jsp by right-clicking View-Controller
    node and selecting New > JSP. Use the wizard to create JSF � JSP Page, fill in
    File Name adduser.jsp, click Finish. -
    <%@page contentType="text/html"%>
    <%@page pageEncoding="UTF-8"%>
    <%@taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
    <%@taglib prefix="h" uri="http://java.sun.com/jsf/html"%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>New user</title>
    </head>
    <body>
    <f:view>
    <h:form>
    <h:messages/>
    <h:panelGrid columns="2">
    <h:outputText value="Username"/>
    <h:inputText
    id="Username"
    value="#{user.user.username}"
    required="true"/>
    <h:outputText value="First name"/>
    <h:inputText
    id="FirstName"
    value="#{user.user.firstName}" />
    <h:outputText value="Last name"/>
    <h:inputText
    id="LastName"
    value="#{user.user.lastName}" />
    <h:outputText value="Password" />
    <h:inputSecret
    id="Password"
    value="#{user.user.password}"
    required="true" />
    <h:panelGroup/>
    <h:commandButton
    action="#{user.saveUser}"
    value="Save"/>
    </h:panelGrid>
    </h:form>
    </f:view>
    </body>
    </html>
    2. Repeat the previous step for another JSP file failed.jsp.
    3. On failed.jsp add the string <h2>Save failed</h2>.
    Next we configure the page flow.
    1. Open faces-config.xml.
    2. Create index.jsp -
    <%@page contentType="text/html"%>
    <%@page pageEncoding="UTF-8"%>
    <%@taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
    <%@taglib prefix="h" uri="http://java.sun.com/jsf/html"%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>User Listing</title>
    </head>
    <body>
    <f:view>
    <h:form>
    <h1><h:outputText value="User Listing"/></h1>
    <p><h:commandLink action="#{user.createUser}" value="Create a user"/></p>
    <h:dataTable value="#{user.user}"
    var="dataTableItem" border="1" cellpadding="2" cellspacing="2">
    <h:column>
    <f:facet name="header">
    <h:outputText value="Username"/>
    </f:facet>
    <h:outputText value="#{dataTableItem.username}" />
    </h:column>
    <h:column>
    <f:facet name="header">
    <h:outputText value="First name"/>
    </f:facet>
    <h:outputText value="#{dataTableItem.firstName}" />
    </h:column>
    <h:column>
    <f:facet name="header">
    <h:outputText value="Last name"/>
    </f:facet>
    <h:outputText value="#{dataTableItem.lastName}" />
    </h:column>
    </h:dataTable>
    </h:form>
    </f:view>
    </body>
    </html>
    3. Drag an arrow from index.jsp to adduser.jsp and replace the arrow�s label to create_new_user.
    4. Repeat the previous step for failed, by dragging and arrow from adduser.jsp to failed.jsp renaming the label to f
    ailed
    5. Finally repeat the step for adduser.jsp, by dragging from adduser.jsp to index.jsp renaming the label to success.
    This creates the following faces-config.xml file �
    <?xml version='1.0' encoding='UTF-8'?>
    <faces-config>
    <managed-bean>
    <managed-bean-name>user</managed-bean-name>
    <managed-bean-class>lux.controllers.UserController</managed-bean-class>
    <managed-bean-scope>session</managed-bean-scope>
    <managed-property>
    <property-name>username</property-name>
    <value>#{username}</value>
    </managed-property>
    <managed-property>
    <property-name>firstName</property-name>
    <value>#{firstName}</value>
    </managed-property>
    <managed-property>
    <property-name>lastName</property-name>
    <value>#{lastName}</value>
    </managed-property>
    <managed-property>
    <property-name>password</property-name>
    <value>#{password}</value>
    </managed-property>
    </managed-bean>
    <navigation-rule>
    <from-view-id>/index.jsp</from-view-id>
    <navigation-case>
    <from-outcome>create_new_user</from-outcome>
    <to-view-id>/adduser.jsp</to-view-id>
    </navigation-case>
    </navigation-rule>
    <navigation-rule>
    <from-view-id>/adduser.jsp</from-view-id>
    <navigation-case>
    <from-outcome>failed</from-outcome>
    <to-view-id>/failed.jsp</to-view-id>
    </navigation-case>
    <navigation-case>
    <from-outcome>success</from-outcome>
    <to-view-id>/index.jsp</to-view-id>
    </navigation-case>
    </navigation-rule>
    </faces-config>
    Step 9: Create a Deployment file in the View-Controller and Deploy this to a WAR file
    Step 10: Create a Deployment file in the View-Controller and create an EAR file and add Model�s JAR and View-Controller�s
    WAR files to it.
    Step 11: Run the JSP Files
    ------------------------------------------------------- SCENARIO END
    Now, When I execute Index.jsp, it does not list values from database and when I click on Create User link, it takes me to adduser.jsp page. When I fill values in this page and click Save button, it takes me to Save Failed page and data does not persist to the database.
    WHAT IS WRONG OUT HERE ???

    PLZZZZZZZZZzzzzzzzzzzz HELP ! ! !

  • EJB-JSF Application : Data does not persist to the database

    Hi,
    I am developing a JSF - EJB application and the data that I send from JSP Page through JSF Managed Bean --> Session Bean --> Java Persistence does not persist in database.
    Here is my scenario ( Iam using JDeveloper IDE to create this application) -
    SCENARIO START
    The scenario consists of two web pages, one enlisting all the users stored in the database, the other contains a form for adding a user
    1.) INDEX.JSP
    2.) ADDUSER.JSP
    Step 1: Create the USERS Table in database
    CREATE TABLE users
    user_id serial,
    username varchar(255) NOT NULL,
    first_name varchar(255),
    last_name varchar(255),
    password char(64) NOT NULL,
    CONSTRAINT pk_users PRIMARY KEY (user_id)
    Step 2: Add Database Connection To JDeveloper
    Go to Database Connection Navigator and create a New Database Connection using the Wizard
    Step 3: Create a New Application in JDeveloper and select JSF, EJB from Application Template
    Step 4: ENTITY BEAN - In the EJB Node Right Click and Select EJB � New Entites from Table (JPA/EJB3.0)
    Use The Wizard and create Entity Bean from Users Table which creates an Entity Bea POJO file as follows �
    User.java -
    package lux.domain;
    import java.io.Serializable;
    import javax.persistence.Column;
    import javax.persistence.Entity;
    import javax.persistence.GeneratedValue;
    import javax.persistence.GenerationType;
    import javax.persistence.Id;
    import javax.persistence.NamedQuery;
    import javax.persistence.SequenceGenerator;
    import javax.persistence.Table;
    @Entity
    @NamedQuery(name = "User.findAll", query = "select o from User o")
    @Table(name = "USERS")
    public class User implements Serializable {
    @Column(name="FIRST_NAME")
    private String firstName;
    @Column(name="LAST_NAME")
    private String lastName;
    @Column(nullable = false)
    private String password;
    @Column(nullable = false)
    private String username;
    @Id
    @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="users_seq_generator")
    @SequenceGenerator(name="users_seq_generator", sequenceName="users_user_id_seq")
    @Column(name="USER_ID", nullable = false)
    private Long userId;
    public User() {
    public String getFirstName() {
    return firstName;
    public void setFirstName(String firstName) {
    this.firstName = firstName;
    public String getLastName() {
    return lastName;
    public void setLastName(String lastName) {
    this.lastName = lastName;
    public String getPassword() {
    return password;
    public void setPassword(String password) {
    this.password = password;
    public String getUsername() {
    return username;
    public void setUsername(String username) {
    this.username = username;
    public Long getUserId() {
    return userId;
    public void setUserId(Long userId) {
    this.userId = userId;
    Step 5: STATELESS SESSION BEAN - In the EJB Node Right Click and Select EJB � New Entites from Table (JPA/EJB3.0)
    Again Right Click on Model and create Session Bean from Wizard which creates two files �
    UserDAOBean.java � Stateless Session Bean
    UserDAO.java � Local Interface
    package lux.facade;
    import java.security.MessageDigest;
    import java.security.NoSuchAlgorithmException;
    import java.util.List;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    import javax.ejb.Stateless;
    import javax.persistence.EntityManager;
    import javax.persistence.PersistenceContext;
    import javax.persistence.Query;
    import lux.domain.User;
    @Stateless(name="UserDAO")
    public class UserDAOBean implements UserDAO {
    @PersistenceContext(unitName="Model")
    private EntityManager em;
    public UserDAOBean() {
    public User getUser(int UserId) {
    User u = new User();
    u = em.find(User.class, UserId);
    return u;
    public List<User> getAllUsers() {
    Query q = em.createQuery("SELECT u FROM User u");
    List<User> users = q.getResultList();
    return users;
    public void createUser(User u) {
    String hashedPw = hashPassword(u.getPassword());
    u.setPassword(hashedPw);
    em.persist(u);
    public void updateUser(User u) {
    String hashedPw = hashPassword(u.getPassword());
    u.setPassword(hashedPw);
    em.merge(u);
    public void deleteUser(User u) {
    em.remove(u);
    private String hashPassword(String password) {
    StringBuilder sb = new StringBuilder();
    try {
    MessageDigest messageDigest = MessageDigest.getInstance("SHA");
    byte[] bs;
    bs = messageDigest.digest(password.getBytes());
    for (int i = 0; i < bs.length; i++) {
    String hexVal = Integer.toHexString(0xFF & bs);
    if (hexVal.length() == 1) {
    sb.append("0");
    sb.append(hexVal);
    } catch (NoSuchAlgorithmException ex) {
    Logger.getLogger(UserDAOBean.class.getName()).log(Level.SEVERE, null, ex);
    return sb.toString();
    Step 6: Create a Deployment file in the Model and Deploy this to a JAR file
    Step 7: Now Right Click on View/Controller Node and create a Java File �
    UserController.java -
    package lux.controllers;
    import javax.ejb.EJB;
    import javax.faces.model.DataModel;
    import javax.faces.model.ListDataModel;
    import lux.domain.User;
    import lux.facade.UserDAO;
    public class UserController {
    @EJB UserDAO userDao;
    private User user;
    private DataModel model;
    public String createUser() {
    this.user = new User();
    return "create_new_user";
    public String saveUser() {
    String r = "success";
    try {
    userDao.createUser(user);
    } catch (Exception e) {
    e.printStackTrace();
    r = "failed";
    return r;
    public DataModel getUsers() {
    model = new ListDataModel(userDao.getAllUsers());
    return model;
    public User getUser() {
    return user;
    public void setUser(User user) {
    this.user = user;
    Step 8: Configure page flow in faces-config.xml
    1. Create the JSP file adduser.jsp by right-clicking View-Controller
    node and selecting New > JSP. Use the wizard to create JSF � JSP Page, fill in
    File Name adduser.jsp, click Finish. -
    <%@page contentType="text/html"%>
    <%@page pageEncoding="UTF-8"%>
    <%@taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
    <%@taglib prefix="h" uri="http://java.sun.com/jsf/html"%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>New user</title>
    </head>
    <body>
    <f:view>
    <h:form>
    <h:messages/>
    <h:panelGrid columns="2">
    <h:outputText value="Username"/>
    <h:inputText
    id="Username"
    value="#{user.user.username}"
    required="true"/>
    <h:outputText value="First name"/>
    <h:inputText
    id="FirstName"
    value="#{user.user.firstName}" />
    <h:outputText value="Last name"/>
    <h:inputText
    id="LastName"
    value="#{user.user.lastName}" />
    <h:outputText value="Password" />
    <h:inputSecret
    id="Password"
    value="#{user.user.password}"
    required="true" />
    <h:panelGroup/>
    <h:commandButton
    action="#{user.saveUser}"
    value="Save"/>
    </h:panelGrid>
    </h:form>
    </f:view>
    </body>
    </html>
    2. Repeat the previous step for another JSP file failed.jsp.
    3. On failed.jsp add the string
    Save failed
    Next we configure the page flow.
    1. Open faces-config.xml.
    2. Create index.jsp -
    <%@page contentType="text/html"%>
    <%@page pageEncoding="UTF-8"%>
    <%@taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
    <%@taglib prefix="h" uri="http://java.sun.com/jsf/html"%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>User Listing</title>
    </head>
    <body>
    <f:view>
    <h:form>
    <h:outputText value="User Listing"/>
    <h:commandLink action="#{user.createUser}" value="Create a user"/>
    <h:dataTable value="#{user.user}"
    var="dataTableItem" border="1" cellpadding="2" cellspacing="2">
    <h:column>
    <f:facet name="header">
    <h:outputText value="Username"/>
    </f:facet>
    <h:outputText value="#{dataTableItem.username}" />
    </h:column>
    <h:column>
    <f:facet name="header">
    <h:outputText value="First name"/>
    </f:facet>
    <h:outputText value="#{dataTableItem.firstName}" />
    </h:column>
    <h:column>
    <f:facet name="header">
    <h:outputText value="Last name"/>
    </f:facet>
    <h:outputText value="#{dataTableItem.lastName}" />
    </h:column>
    </h:dataTable>
    </h:form>
    </f:view>
    </body>
    </html>
    3. Drag an arrow from index.jsp to adduser.jsp and replace the arrow�s label to create_new_user.
    4. Repeat the previous step for failed, by dragging and arrow from adduser.jsp to failed.jsp renaming the label to f
    ailed
    5. Finally repeat the step for adduser.jsp, by dragging from adduser.jsp to index.jsp renaming the label to success.
    This creates the following faces-config.xml file �
    <?xml version='1.0' encoding='UTF-8'?>
    <faces-config>
    <managed-bean>
    <managed-bean-name>user</managed-bean-name>
    <managed-bean-class>lux.controllers.UserController</managed-bean-class>
    <managed-bean-scope>session</managed-bean-scope>
    <managed-property>
    <property-name>username</property-name>
    <value>#{username}</value>
    </managed-property>
    <managed-property>
    <property-name>firstName</property-name>
    <value>#{firstName}</value>
    </managed-property>
    <managed-property>
    <property-name>lastName</property-name>
    <value>#{lastName}</value>
    </managed-property>
    <managed-property>
    <property-name>password</property-name>
    <value>#{password}</value>
    </managed-property>
    </managed-bean>
    <navigation-rule>
    <from-view-id>/index.jsp</from-view-id>
    <navigation-case>
    <from-outcome>create_new_user</from-outcome>
    <to-view-id>/adduser.jsp</to-view-id>
    </navigation-case>
    </navigation-rule>
    <navigation-rule>
    <from-view-id>/adduser.jsp</from-view-id>
    <navigation-case>
    <from-outcome>failed</from-outcome>
    <to-view-id>/failed.jsp</to-view-id>
    </navigation-case>
    <navigation-case>
    <from-outcome>success</from-outcome>
    <to-view-id>/index.jsp</to-view-id>
    </navigation-case>
    </navigation-rule>
    </faces-config>
    Step 9: Create a Deployment file in the View-Controller and Deploy this to a WAR file
    Step 10: Create a Deployment file in the View-Controller and create an EAR file and add Model�s JAR and View-Controller�s
    WAR files to it.
    Step 11: Run the JSP Files
    SCENARIO END
    Now, When I execute Index.jsp, it does not list values from database and when I click on Create User link, it takes me to adduser.jsp page. When I fill values in this page and click Save button, it takes me to Save Failed page and data does not persist to the database.
    WHAT IS WRONG OUT HERE ???

    If you set a breakpoint in your createUser method - does this code get executed?
    We have a couple of tutorials that might show you how to do this.
    EJB/JSF with ADF-binding tutorial:
    http://www.oracle.com/technology/obe/obe1013jdev/10131/ejb_and_jpa/master-detail_pagewith_ejb.htm
    EJB/JSF without ADF binding:
    http://www.oracle.com/technology/obe/JavaEE_tutorial_10131/index.htm

  • Column name in the database starts with a number!

    Hello,
    Recently we updated out database and we changed our tables' and columns' names, I'm developing an adf application with EJB3.0 the question is that the new column names start with a number (eg. 001U_ID), its a kind of encoding the names of the tables so no one can modify the values.
    When I create a query on the table it is throwing an exception:
    Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: Incorrect syntax near 'U_ID'.
    I think the problem is that the EJB3.0 doesn't recognize column names starting with a number!!! What can I do to solve this issue?
    Thanks
    Shahe

    Shahe wrote:
    the entities are declared using the database tables, I'm using EJBQL to retrieve data from the tables.Can you explain this more. Are you using JPA entities? If so post the definition of the Entity bean and the query you used.

  • Tool to create Java Object classes using the Database Tables

    Hi,
    Is their any tools or utility available to create the Java Object Classes using the Database Tables as input.
    Lets Say I am having the Employee, Employee_Salary tables in the Database.The utility has to create the Java Object classes with the relation.
    Please Help...
    Thx..

    Hm, for generating regular Java classes I wouldn't know one from memory. But I suggest you start searching in for example the Eclipse marketspace for a third party plugin that can do it. If all fail, you could always use Hibernate Tools from the Jboss Tools Eclipse plugin set to generate Hibernate/JPA entities and then strip the annotations from them to turn them into regular POJO classes.
    How many tables are we talking about anyway? It might be less effort to just create the classes with properties and then use an IDE to generate getters and setters for them.

  • Error received on creating jpa entities

    Hello,
    I am using jdeveloper 11.1.1.7 and am working with a simple test of creating a row in a table.  I have created the Jpa entities as described on
    Oracle JDeveloper 11g Release 2 Tutorials - Building a JPA Application and
    EJB 3.0 component exposed as webservice using Oracle JDeveloper: Create simple EJB component, exposed it as a webservice…
    which deals more with creating an actual row in the table.
    I run it and I get a huge list of depreciated methods and an error.  It does load the data, which is great, but I cannot use this in production with all the errors produced!
    This is pretty bad considering most of the code was generated using the wizards....
    Any ideas?
    C:\Oracle11117\Middleware\jdk160_24\bin\javaw.exe -client -classpath C:\JDeveloper\mywork\XML\.adf;C:\JDeveloper\mywork\XML\Jpa_EntitiesAgain\classes;C:\Oracle11117\Middleware\modules\com.oracle.toplink_1.0.0.0_11-1-1-5-0.jar;C:\Oracle11117\Middleware\modules\org.eclipse.persistence_1.1.0.0_2-1.jar;C:\Oracle11117\Middleware\modules\com.bea.core.antlr.runtime_2.7.7.jar;C:\Oracle11117\Middleware\modules\javax.persistence_1.0.0.0_2-0-0.jar;C:\Oracle11117\Middleware\oracle_common\modules\oracle.xdk_11.1.0\xmlparserv2.jar;C:\Oracle11117\Middleware\oracle_common\modules\oracle.xdk_11.1.0\xml.jar;C:\Oracle11117\Middleware\modules\javax.jsf_1.1.0.0_1-2.jar;C:\Oracle11117\Middleware\modules\javax.ejb_3.0.1.jar;C:\Oracle11117\Middleware\modules\javax.enterprise.deploy_1.2.jar;C:\Oracle11117\Middleware\modules\javax.interceptor_1.0.jar;C:\Oracle11117\Middleware\modules\javax.jms_1.1.1.jar;C:\Oracle11117\Middleware\modules\javax.jsp_1.2.0.0_2-1.jar;C:\Oracle11117\Middleware\modules\javax.jws_2.0.jar;C:\Oracle11117\Middleware\modules\javax.activation_1.1.0.0_1-1.jar;C:\Oracle11117\Middleware\modules\javax.mail_1.1.0.0_1-4-1.jar;C:\Oracle11117\Middleware\modules\javax.xml.soap_1.3.1.0.jar;C:\Oracle11117\Middleware\modules\javax.xml.rpc_1.2.1.jar;C:\Oracle11117\Middleware\modules\javax.xml.ws_2.1.1.jar;C:\Oracle11117\Middleware\modules\javax.management.j2ee_1.0.jar;C:\Oracle11117\Middleware\modules\javax.resource_1.5.1.jar;C:\Oracle11117\Middleware\modules\javax.servlet_1.0.0.0_2-5.jar;C:\Oracle11117\Middleware\modules\javax.transaction_1.0.0.0_1-1.jar;C:\Oracle11117\Middleware\modules\javax.xml.stream_1.1.1.0.jar;C:\Oracle11117\Middleware\modules\javax.security.jacc_1.0.0.0_1-1.jar;C:\Oracle11117\Middleware\modules\javax.xml.registry_1.0.0.0_1-0.jar;C:\Oracle11117\Middleware\jdeveloper\ide\macros\..\..\..\oracle_common\modules\oracle.jdbc_11.1.1\ojdbc6dms.jar;C:\Oracle11117\Middleware\jdeveloper\ide\macros\..\..\..\oracle_common\modules\oracle.nlsrtl_11.1.0\orai18n.jar;C:\Oracle11117\Middleware\oracle_common\modules\oracle.odl_11.1.1\ojdl.jar;C:\Oracle11117\Middleware\oracle_common\modules\oracle.dms_11.1.1\dms.jar -Djavax.net.ssl.trustStore=C:\Oracle11117\Middleware\wlserver_10.3\server\lib\DemoTrust.jks jpa_entities.Serve.JavaServiceFacade
    [EL Info]: 2013-10-07 15:35:17.703--ServerSession(13419912)--Thread(Thread[main,5,main])--property eclipselink.jdbc.user is deprecated, property javax.persistence.jdbc.user should be used instead.
    [EL Info]: 2013-10-07 15:35:17.703--ServerSession(13419912)--Thread(Thread[main,5,main])--property eclipselink.jdbc.driver is deprecated, property javax.persistence.jdbc.driver should be used instead.
    [EL Info]: 2013-10-07 15:35:17.703--ServerSession(13419912)--Thread(Thread[main,5,main])--property eclipselink.jdbc.url is deprecated, property javax.persistence.jdbc.url should be used instead.
    [EL Info]: 2013-10-07 15:35:17.703--ServerSession(13419912)--Thread(Thread[main,5,main])--property eclipselink.jdbc.password is deprecated, property javax.persistence.jdbc.password should be used instead.
    [EL Finer]: 2013-10-07 15:35:17.718--ServerSession(13419912)--Thread(Thread[main,5,main])--Searching for default mapping file in file:/C:/JDeveloper/mywork/XML/Jpa_EntitiesAgain/classes/
    [EL Finer]: 2013-10-07 15:35:17.734--ServerSession(13419912)--Thread(Thread[main,5,main])--Searching for default mapping file in file:/C:/JDeveloper/mywork/XML/Jpa_EntitiesAgain/classes/
    [EL Config]: 2013-10-07 15:35:17.812--ServerSession(13419912)--Thread(Thread[main,5,main])--The access type for the persistent class [class jpa_entities.JpaTest] is set to [FIELD].
    [EL Config]: 2013-10-07 15:35:17.828--ServerSession(13419912)--Thread(Thread[main,5,main])--The alias name for the entity class [class jpa_entities.JpaTest] is being defaulted to: JpaTest.
    [EL Config]: 2013-10-07 15:35:17.843--ServerSession(13419912)--Thread(Thread[main,5,main])--The column name for element [field test1] is being defaulted to: TEST1.
    [EL Config]: 2013-10-07 15:35:17.843--ServerSession(13419912)--Thread(Thread[main,5,main])--The column name for element [field test2] is being defaulted to: TEST2.
    [EL Finer]: 2013-10-07 15:35:17.843--Thread(Thread[main,5,main])--JavaSECMPInitializer - transformer is null.
    [EL Info]: 2013-10-07 15:35:17.843--ServerSession(13419912)--Thread(Thread[main,5,main])--property eclipselink.jdbc.user is deprecated, property javax.persistence.jdbc.user should be used instead.
    [EL Info]: 2013-10-07 15:35:17.843--ServerSession(13419912)--Thread(Thread[main,5,main])--property eclipselink.jdbc.driver is deprecated, property javax.persistence.jdbc.driver should be used instead.
    [EL Info]: 2013-10-07 15:35:17.843--ServerSession(13419912)--Thread(Thread[main,5,main])--property eclipselink.jdbc.url is deprecated, property javax.persistence.jdbc.url should be used instead.
    [EL Info]: 2013-10-07 15:35:17.843--ServerSession(13419912)--Thread(Thread[main,5,main])--property eclipselink.jdbc.password is deprecated, property javax.persistence.jdbc.password should be used instead.
    [EL Finer]: 2013-10-07 15:35:17.859--ServerSession(13419912)--Thread(Thread[main,5,main])--Could not initialize Validation Factory. Encountered following exception: java.lang.NoClassDefFoundError: javax/validation/Validation
    [EL Info]: 2013-10-07 15:35:18.25--ServerSession(13419912)--Thread(Thread[main,5,main])--EclipseLink, version: Eclipse Persistence Services - 2.1.3.v20110304-r9073
    [EL Warning]: 2013-10-07 15:35:18.25--Thread(Thread[main,5,main])--java.lang.ClassNotFoundException: weblogic.version
      at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:305)
      at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:246)
      at java.lang.Class.forName0(Native Method)
      at java.lang.Class.forName(Class.java:169)
      at org.eclipse.persistence.internal.security.PrivilegedAccessHelper.getClassForName(PrivilegedAccessHelper.java:81)
      at org.eclipse.persistence.platform.server.wls.WebLogicPlatform.initializeServerNameAndVersion(WebLogicPlatform.java:85)
      at org.eclipse.persistence.platform.server.ServerPlatformBase.getServerNameAndVersion(ServerPlatformBase.java:181)
      at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.preConnectDatasource(DatabaseSessionImpl.java:653)
      at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.loginAndDetectDatasource(DatabaseSessionImpl.java:576)
      at org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.login(EntityManagerFactoryProvider.java:228)
      at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:389)
      at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.getServerSession(EntityManagerFactoryImpl.java:164)
      at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:221)
      at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:209)
      at jpa_entities.Serve.JavaServiceFacade.getEntityManager(JavaServiceFacade.java:37)
      at jpa_entities.Serve.JavaServiceFacade._persistEntity(JavaServiceFacade.java:53)
      at jpa_entities.Serve.JavaServiceFacade.persistJpaTest(JavaServiceFacade.java:75)
      at jpa_entities.Serve.JavaServiceFacade.main(JavaServiceFacade.java:32)
    [EL Fine]: 2013-10-07 15:35:18.812--Thread(Thread[main,5,main])--Detected Vendor platform: org.eclipse.persistence.platform.database.oracle.Oracle10Platform
    [EL Config]: 2013-10-07 15:35:18.828--ServerSession(13419912)--Connection(21411547)--Thread(Thread[main,5,main])--connecting(DatabaseLogin(
      platform=>Oracle10Platform
      user name=> "stuartf"
      datasource URL=> "jdbc:oracle:thin:@lpgtr82:1521:test11g"
    [EL Config]: 2013-10-07 15:35:18.859--ServerSession(13419912)--Connection(15399793)--Thread(Thread[main,5,main])--Connected: jdbc:oracle:thin:@lpgtr82:1521:test11g
      User: STUARTF
      Database: Oracle  Version: Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options
      Driver: Oracle JDBC driver  Version: 11.2.0.3.0
    [EL Info]: 2013-10-07 15:35:19.078--ServerSession(13419912)--Thread(Thread[main,5,main])--file:/C:/JDeveloper/mywork/XML/Jpa_EntitiesAgain/classes/_Jpa_EntitiesAgain-1 login successful
    [EL Warning]: 2013-10-07 15:35:19.078--ServerSession(13419912)--Thread(Thread[main,5,main])--Failed to find MBean Server: javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:  java.naming.factory.initial
    [EL Warning]: 2013-10-07 15:35:19.078--ServerSession(13419912)--Thread(Thread[main,5,main])--Failed to find MBean Server: javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:  java.naming.factory.initial
    [EL Warning]: 2013-10-07 15:35:19.078--ServerSession(13419912)--Thread(Thread[main,5,main])--Failed to find MBean Server: javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:  java.naming.factory.initial
    [EL Finer]: 2013-10-07 15:35:19.093--ServerSession(13419912)--Thread(Thread[main,5,main])--Canonical Metamodel class [jpa_entities.JpaTest_] not found during initialization.
    [EL Finer]: 2013-10-07 15:35:19.109--ServerSession(13419912)--Thread(Thread[main,5,main])--client acquired
    [EL Finer]: 2013-10-07 15:35:19.109--UnitOfWork(7819553)--Thread(Thread[main,5,main])--begin unit of work commit
    [EL Finer]: 2013-10-07 15:35:19.109--ClientSession(32803057)--Connection(15399793)--Thread(Thread[main,5,main])--begin transaction
    [EL Fine]: 2013-10-07 15:35:19.125--ClientSession(32803057)--Connection(15399793)--Thread(Thread[main,5,main])--INSERT INTO JPA_TEST (JPA_TEST_ID, TEST1, TEST2) VALUES (?, ?, ?)
      bind => [2, hello, there]
    [EL Finer]: 2013-10-07 15:35:19.203--ClientSession(32803057)--Connection(15399793)--Thread(Thread[main,5,main])--commit transaction
    [EL Finer]: 2013-10-07 15:35:19.218--UnitOfWork(7819553)--Thread(Thread[main,5,main])--end unit of work commit
    [EL Finer]: 2013-10-07 15:35:19.218--UnitOfWork(7819553)--Thread(Thread[main,5,main])--resume unit of work
    [EL Finer]: 2013-10-07 15:35:19.218--UnitOfWork(7819553)--Thread(Thread[main,5,main])--release unit of work
    [EL Finer]: 2013-10-07 15:35:19.218--ClientSession(32803057)--Thread(Thread[main,5,main])--client released
    Process exited with exit code 0.

    The error seems caused by the persistence.xml specifying that EclipseLink should use the weblogic server platform, but you are not running your example within WLS.  This causes an internal exception when it tries to load WebLogic classes which are unavailable.  It is only printing off the exception at the warning level to indicate you do not have the correct settings for your test environment. 
    Ideally you would only want the log level set to severe or off in production, as any exceptions would be propagated up to the application anyway.
    Best Regards,
    Chris

  • Closing the database connection after report in a server application

    I searched these forums and the internet for a definitive answer on asking the Crystal SDK for java to close the jdbc connection after it has generated a report.  We have been using the Crystal Report SDK to generate reports within our JEE application, built upon the Spring framework, for the past two years.  It works well, especially if you prepare views in the database for your reports.
    From what I can tell once you have used ReportClientDocument to create your report you all the close() method to release resources associated with report generation, but this does not close the jdbc database connection.
    Further research states that if you are using the CrystalReportViewer you can call the dispose method to close the database connection.  We are not using JSP nor this class, so that does us little good.
    Finally I found a post that one could call ((AdvancedReportDocument)reportClientDocument.getReportSource()).dispose().  This doesn't drop the connection either.
    Each report actually opens 3 connections according to SQL Server.  Each report will reuse the connections it has open, so for 50 reports, theoretically, we could have up to 150 connections.  We explained to our client those connections  remain inactive, however this is unacceptable to our client as they would like to minimize the number of connections left open to their database.
    If anyone can post any further information on this issue, it is much appreciated.

    Yes, another team member found the issue.  Quite embarrassing really I didn't see it.  I was looking for the answer within Crystal's libraries.  It had nothing to do with Crystal.
    The developer who wrote the helper code for using Crystal first opened a connection to the datasource for the live production database and read that connection information for the report. Next he set that connection information in the report template's PropertyBag, then ran the report. The developer however forgot to close the connection he used to look up the connection info, leaving a memory leak and using up all the connections.
    I'm glad you inquired.  I forgot to post the resolution here.

  • Can not see any entities in The ER diagram

    I am trying to create an ER diagram from an existing database. I am using designer 10.1. I generated a server model, the table to entity retrofit successfully. I can see all the entities and attributes in the RON. But when I try to create ER diagram , I don't see any entities or attributes. Am I missing something ??
    Any help???? Thanks in advance..

    If version control is not turned on, then there is only one workarea, "GLOBAL SHARED WORKAREA" and EVERYTHING is in it. So that isn't the problem.
    Let's step through this a little:
    You start the E/R diagrammer and open a new diagram.
    You are prompted to Select a default container for this diagram, and you probably selected the application (an application is one of two types of containers) where you created the entities.
    So you have a blank diagram.
    You select the Edit menu, and "Include...", "Entity".
    You should get a window with a navigator in it, with the entities in the default container showing.
    If not, you should be able to open the tree to view and select those entities.
    Is this where you don't get the list of entities that you expected to see?
    One possible problem is Access Rights - in RON, right click the application, and choose "View Access Rights". Make sure that your username has the right to SELECT that application. By the way, you ARE using a username other than the owner of the repository, right? The only time you should connect as the repository owner is in the RAU. Use the RAU to grant another user (have the DBA create another user, if you haven't already) access to the repository. Then, in RON, make that user the owner of your application.

  • How to create a cache for JPA Entities using an EJB

    Hello everybody! I have recently got started with JPA 2.0 (I use eclipseLink) and EJB 3.1 and have a problem to figure out how to best implement a cache for my JPA Entities using an EJB.
    In the following I try to describe my problem.. I know it is a bit verbose, but hope somebody will help me.. (I highlighted in bold the core of my problem, in case you want to first decide if you can/want help and in the case spend another couple of minutes to understand the domain)
    I have the following JPA Entities:
    @Entity Genre{
    private String name;
    @OneToMany(mappedBy = "genre", cascade={CascadeType.MERGE, CascadeType.PERSIST})
    private Collection<Novel> novels;
    @Entity
    class Novel{
    @ManyToOne(cascade={CascadeType.MERGE, CascadeType.PERSIST})
    private Genre genre;
    private String titleUnique;
    @OneToMany(mappedBy="novel", cascade={CascadeType.MERGE, CascadeType.PERSIST})
    private Collection<NovelEdition> editions;
    @Entity
    class NovelEdition{
    private String publisherNameUnique;
    private String year;
    @ManyToOne(optional=false, cascade={CascadeType.PERSIST, CascadeType.MERGE})
    private Novel novel;
    @ManyToOne(optional=false, cascade={CascadeType.MERGE, CascadeType.PERSIST})
    private Catalog appearsInCatalog;
    @Entity
    class Catalog{
    private String name;
    @OneToMany(mappedBy = "appearsInCatalog", cascade = {CascadeType.MERGE, CascadeType.PERSIST})
    private Collection<NovelEdition> novelsInCatalog;
    The idea is to have several Novels, belonging each to a specific Genre, for which can exist more than an edition (different publisher, year, etc). For semplicity a NovelEdition can belong to just one Catalog, being such a Catalog represented by such a text file:
    FILE 1:
    Catalog: Name Of Catalog 1
    "Title of Novel 1", "Genre1 name","Publisher1 Name", 2009
    "Title of Novel 2", "Genre1 name","Pulisher2 Name", 2010
    FILE 2:
    Catalog: Name Of Catalog 2
    "Title of Novel 1", "Genre1 name","Publisher2 Name", 2011
    "Title of Novel 2", "Genre1 name","Pulisher1 Name", 2011
    Each entity has associated a Stateless EJB that acts as a DAO, using a Transaction Scoped EntityManager. For example:
    @Stateless
    public class NovelDAO extends AbstractDAO<Novel> {
    @PersistenceContext(unitName = "XXX")
    private EntityManager em;
    protected EntityManager getEntityManager() {
    return em;
    public NovelDAO() {
    super(Novel.class);
    //NovelDAO Specific methods
    I am interested at when the catalog files are parsed and the corresponding entities are built (I usually read a whole batch of Catalogs at a time).
    Being the parsing a String-driven procedure, I don't want to repeat actions like novelDAO.getByName("Title of Novel 1") so I would like to use a centralized cache for mappings of type String-Identifier->Entity object.
    Currently I use +3 Objects+:
    1) The file parser, which does something like:
    final CatalogBuilder catalogBuilder = //JNDI Lookup
    //for each file:
    String catalogName = parseCatalogName(file);
    catalogBuilder.setCatalogName(catalogName);
    //For each novel edition
    String title= parseNovelTitle();
    String genre= parseGenre();
    catalogBuilder.addNovelEdition(title, genre, publisher, year);
    //End foreach
    catalogBuilder.build();
    2) The CatalogBuilder is a Stateful EJB which uses the Cache and gets re-initialized every time a new Catalog file is parsed and gets "removed" after a catalog is persisted.
    @Stateful
    public class CatalogBuilder {
    @PersistenceContext(unitName = "XXX", type = PersistenceContextType.EXTENDED)
    private EntityManager em;
    @EJB
    private Cache cache;
    private Catalog catalog;
    @PostConstruct
    public void initialize() {
    catalog = new Catalog();
    catalog.setNovelsInCatalog(new ArrayList<NovelEdition>());
    public void addNovelEdition(String title, String genreStr, String publisher, String year){
    Genre genre = cache.findGenreCreateIfAbsent(genreStr);//##
    Novel novel = cache.findNovelCreateIfAbsent(title, genre);//##
    NovelEdition novEd = new NovelEdition();
    novEd.setNovel(novel);
    //novEd.set publisher year catalog
    catalog.getNovelsInCatalog().add();
    public void setCatalogName(String name) {
    catalog.setName(name);
    @Remove
    public void build(){
    em.merge(catalog);
    3) Finally, the problematic bean: Cache. For CatalogBuilder I used an EXTENDED persistence context (which I need as the Parser executes several succesive transactions) together with a Stateful EJB; but in this case I am not really sure what I need. In fact, the cache:
    Should stay in memory until the parser is finished with its job, but not longer (should not be a singleton) as the parsing is just a very particular activity which happens rarely.
    Should keep all of the entities in context, and should return managed entities form mehtods marked with ##, otherwise the attempt to persist the catalog should fail (duplicated INSERTs)..
    Should use the same persistence context as the CatalogBuilder.
    What I have now is :
    @Stateful
    public class Cache {
    @PersistenceContext(unitName = "XXX", type = PersistenceContextType.EXTENDED)
    private EntityManager em;
    @EJB
    private sessionbean.GenreDAO genreDAO;
    //DAOs for other cached entities
    Map<String, Genre> genreName2Object=new TreeMap<String, Genre>();
    @PostConstruct
    public void initialize(){
    for (Genre g: genreDAO.findAll()) {
    genreName2Object.put(g.getName(), em.merge(g));
    public Genre findGenreCreateIfAbsent(String genreName){
    if (genreName2Object.containsKey(genreName){
    return genreName2Object.get(genreName);
    Genre g = new Genre();
    g.setName();
    g.setNovels(new ArrayList<Novel>());
    genreDAO.persist(t);
    genreName2Object.put(t.getIdentifier(), em.merge(t));
    return t;
    But honestly I couldn't find a solution which satisfies these 3 points at the same time. For example, using another stateful bean with an extended persistence context (PC) would work for the 1st parsed file, but I have no idea what should happen from the 2nd file on.. Indeed, for the 1st file the PC will be created and propagated from CatalogBuilder to Cache, which will then use the same PC. But after build() returns, the PC of CatalogBuilder should (I guess) be removed and re-created during the succesive parsing, although the PC of Cache should stay "alive": shouldn't in this case an exception being thrown? Another problem is what to do when the Cache bean is passivated. Currently I get the exception:
    "passivateEJB(), Exception caught ->
    java.io.IOException: java.io.IOException
    at com.sun.ejb.base.io.IOUtils.serializeObject(IOUtils.java:101)
    at com.sun.ejb.containers.util.cache.LruSessionCache.saveStateToStore(LruSessionCache.java:501)"
    Hence, I have no Idea how to implement my cache.. Can you please tell me how would you solve the problem?
    Many thanks!
    Bye

    Hi Chris,
    thanks for your reply!
    I've tried to add the following into persistence.xml (although I've read that eclipseLink uses L2 cache by default..):
    <shared-cache-mode>ALL</shared-cache-mode>
    Then I replaced the Cache bean with a stateless bean which has methods like
    Genre findGenreCreateIfAbsent(String genreName){
    Genre genre = genreDAO.findByName(genreName);
    if (genre!=null){
    return genre;
    genre = //Build new genre object
    genreDAO.persist(genre);
    return genre;
    As far as I undestood, the shared cache should automatically store the genre and avoid querying the DB multiple times for the same genre, but unfortunately this is not the case: if I use a FINE logging level, I see really a lot of SELECT queries, which I didn't see with my "home made" Cache...
    I am really confused.. :(
    Thanks again for helping + bye

  • SE14 Status-UPGRADE-Table does not exist in the database

    Folks,
    I have created a ztable with SPRAS and few Char fields and generated a table maintenance generator.In the Dev it is working fine but when I moved the TR to Q TR ended up with errrors "Generation of Programs and Screens".When I check in Q in SE11 I am able to see the table but with an error message "Table doesn't exist in the database".
    SE14 Status for this table is getting shown as UPGRADE in Q.
    Can anyone here throw some light on what exactly this status UPGRADE means and how it gets set in SE14.
    In DEV,I had checked the DATABASE OBJECT>>CHECK>DISPLAY and RUNTIME OBJECT>>CHECK>>DISPLAY and it is showing Database object is consistent but where as the same in Q is showing "Table is not created in the Database".
    K.Kiran.

    Hi.
    Is Q system is newly copied? Also please check the transport order of the table creation request. Also check whether pwd of the DB user is locked?
    Regards,
    Vimal

  • EJB 3.0 JPA Entities and preserving user identities

    Hello all,
    I've been reading about some of the techniques available to Oracle DB developers to ensure that some sense of a user's real identity is maintained in multitier applications (<http://download-uk.oracle.com/docs/cd/B19306_01/network.102/b14266/apdvprxy.htm>).
    I was wondering if either of the methods described (proxy authentication or the use of the CLIENT_IDENTIFIER attribute) could be used in conjunction with EJB 3.0 JPA Entity beans (in an OC4J container).
    If so, I would really appreciate any pointers to useful documentation! I've read something about the use of proxy authentication with TopLink (<http://www.oracle.com/technology/products/ias/toplink/doc/11110/relnotes/toplink-relnotes.html#BABHEFEF>), but I'm not sure how this relates to the use of Entity beans.
    Many thanks,
    Alistair.

    Just to close this thread out...
    Under another thread: <JPA Entities with Proxy Authentication / OC4J bug it was determined that this is NOT possible with OC4J 10g, but should be supported by 11g.
    Alistair.

Maybe you are looking for