glassfish
  1. glassfish
  2. GLASSFISH-11304

Hibernate peristence provider does not work if the entity manager is injected using annotated field.

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Incomplete
    • Affects Version/s: 9.0pe
    • Fix Version/s: V3
    • Component/s: entity-persistence
    • Labels:
      None
    • Environment:

      Operating System: All
      Platform: Linux

    • Issuezilla Id:
      11,304

      Description

      When I use Hibernate as a persistence provider, the construct

      @PersistenceContext(unitName = "bigproject", name = "bigproject")
      private EntityManager em;

      does something (as the em field is not null) but it any attempt to use if raises
      the following exception:

      Caused by: java.sql.SQLException: Error in allocating a connection. Cause:
      Connection could not be allocated because: java.net.ConnectException : Error
      connecting to server localhost on port 1527 with message Connection refused.
      at com.sun.gjc.spi.base.DataSource.getConnection(DataSource.java:133)
      at
      org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider.getConnection(InjectedDataSourceConnectionProvider.java:68)
      at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:446)
      ... 71 more

      Here we see a wrong port, 1527 (Postgresql runs on its default 5432).

      Hibernate persistence with Postgresql works flawlessly if introduced in the
      following way:

      EntityManagerFactory factory = Persistence
      .createEntityManagerFactory("bigproject");
      em = factory.createEntityManager();

      Same peristence.xml is used in both cases. Postgresql is running on a local host
      and is both functional and reachable, as the bean using the second version of
      the code works at the same deployment.

        Activity

        Hide
        audriusa added a comment -

        Created an attachment (id=4092)
        The persistence.xml file that works with one beand and does not work in another.

        Show
        audriusa added a comment - Created an attachment (id=4092) The persistence.xml file that works with one beand and does not work in another.
        Hide
        ksak added a comment -

        Not an EJB issue. Reassigning to entity persistence for further analysis.

        Show
        ksak added a comment - Not an EJB issue. Reassigning to entity persistence for further analysis.
        Hide
        Mitesh Meswani added a comment -

        Your are most probably not specifying <jta-data-source> in your persistence.xml.
        GlassFish in this case defaults to datasource jdbc/__default that points to
        Derby running on port 1527.

        The case of Persistence.createEMF works as you might be specifying hibernate.*
        properties pointing to your Postgresql instance.

        Please reopen attaching your persistence.xml is above is not the case.

        Show
        Mitesh Meswani added a comment - Your are most probably not specifying <jta-data-source> in your persistence.xml. GlassFish in this case defaults to datasource jdbc/__default that points to Derby running on port 1527. The case of Persistence.createEMF works as you might be specifying hibernate.* properties pointing to your Postgresql instance. Please reopen attaching your persistence.xml is above is not the case.

          People

          • Assignee:
            Mitesh Meswani
            Reporter:
            audriusa
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: