facebook

persistence.xml

  1. MyEclipse IDE
  2.  > 
  3. Java EE Development (EJB, JSP, Struts, XDoclet, etc.)
Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #271845 Reply

    maximuszen
    Member

    I have a EJB 3 entity bean. How do I write a persistence.xml for it? I’m using postgres, hibernate.

    #271871 Reply

    Riyad Kalla
    Member

    Maximumszen,
    If you created an EJB 3 project, during the project-creation step, you should have been asked to configure the persistence information for the project. In MyEclipse 6.0 we will provide facilities to generate persistence units for you after the project has been created.

    #271875 Reply

    maximuszen
    Member

    when will eclipse 6 be out

    #271882 Reply

    Riyad Kalla
    Member

    If you mean MyEclipse 6.0, it will be out next month.

    #271883 Reply

    maximuszen
    Member

    when i try to reverse engineer a table to ejb 3 it asks for the source folder for whatever reason i get no choices for a sorce folder despite having one in my ejb progject src

    #271884 Reply

    Riyad Kalla
    Member

    That could be for a couple of reasons:

    1) Your project is not an EJB (Java EE 5/EJB 3) Project.
    2) Your project is a plain Web Project or Java project.
    3) Your project doesn’t have JPA Capabilities added to it (implied by #1)

    #271896 Reply

    maximuszen
    Member

    Thank you. I did it yesterday and…

    #271915 Reply

    maximuszen
    Member

    This is my persistence.xml

    <?xml version=”1.0″ encoding=”UTF-8″?>
    <persistence xmlns=”http://java.sun.com/xml/ns/persistence&#8221;
    xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance&#8221;
    xsi:schemaLocation=”http://java.sun.com/xml/ns/persistence
    http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd&#8221; version=”1.0″>

    <persistence-unit name=”p” transaction-type=”JTA”>
    <jta-data-source>java:/PostgresDS</jta-data-source>
    <properties>
    <property name=”hibernate.hbm2ddl.auto” value=”update” />
    </properties>
    </persistence-unit>

    </persistence>

    but I get the error below

    14:20:52,265 INFO [JmxKernelAbstraction] creating wrapper delegate for: org.jboss.ejb3.entity.PersistenceUnitDeployment
    14:20:52,265 INFO [JmxKernelAbstraction] installing MBean: persistence.units:jar=Test.jar,unitName=p with dependencies:
    14:20:52,265 INFO [JmxKernelAbstraction] jboss.jca:name=PostgresDS,service=DataSourceBinding
    14:20:52,281 INFO [PersistenceUnitDeployment] Starting persistence unit persistence.units:jar=Test.jar,unitName=p
    14:20:52,296 INFO [Ejb3Configuration] found EJB3 Entity bean: ejb.T2
    14:20:52,312 INFO [Ejb3Configuration] found EJB3 Entity bean: ejb.T3
    14:20:52,312 WARN [Ejb3Configuration] Persistence provider caller does not implements the EJB3 spec correctly. PersistenceUnitInfo.getNewTempClassLoader() is null.
    14:20:52,343 INFO [Configuration] Reading mappings from resource : META-INF/orm.xml
    14:20:52,343 INFO [Ejb3Configuration] [PersistenceUnit: p] no META-INF/orm.xml found
    14:20:52,359 INFO [AnnotationBinder] Binding entity from annotated class: ejb.T2
    14:20:52,359 INFO [EntityBinder] Bind entity ejb.T2 on table t2
    14:20:52,359 INFO [AnnotationBinder] Binding entity from annotated class: ejb.T3
    14:20:52,359 INFO [EntityBinder] Bind entity ejb.T3 on table T3
    14:20:52,390 INFO [ConnectionProviderFactory] Initializing connection provider: org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider
    14:20:52,390 INFO [InjectedDataSourceConnectionProvider] Using provided datasource
    14:20:52,390 INFO [SettingsFactory] RDBMS: PostgreSQL, version: 8.2.4
    14:20:52,390 INFO [SettingsFactory] JDBC driver: PostgreSQL Native Driver, version: PostgreSQL 8.2 JDBC3 with SSL (build 505)
    14:20:52,390 INFO [Dialect] Using dialect: org.hibernate.dialect.PostgreSQLDialect
    14:20:52,390 INFO [TransactionFactoryFactory] Transaction strategy: org.hibernate.ejb.transaction.JoinableCMTTransactionFactory
    14:20:52,390 INFO [TransactionManagerLookupFactory] instantiating TransactionManagerLookup: org.hibernate.transaction.JBossTransactionManagerLookup
    14:20:52,390 INFO [TransactionManagerLookupFactory] instantiated TransactionManagerLookup
    14:20:52,390 INFO [SettingsFactory] Automatic flush during beforeCompletion(): disabled
    14:20:52,390 INFO [SettingsFactory] Automatic session close at end of transaction: disabled
    14:20:52,390 INFO [SettingsFactory] JDBC batch size: 15
    14:20:52,390 INFO [SettingsFactory] JDBC batch updates for versioned data: disabled
    14:20:52,390 INFO [SettingsFactory] Scrollable result sets: enabled
    14:20:52,390 INFO [SettingsFactory] JDBC3 getGeneratedKeys(): disabled
    14:20:52,390 INFO [SettingsFactory] Connection release mode: auto
    14:20:52,390 INFO [SettingsFactory] Default batch fetch size: 1
    14:20:52,390 INFO [SettingsFactory] Generate SQL with comments: disabled
    14:20:52,390 INFO [SettingsFactory] Order SQL updates by primary key: disabled
    14:20:52,390 INFO [SettingsFactory] Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
    14:20:52,390 INFO [ASTQueryTranslatorFactory] Using ASTQueryTranslatorFactory
    14:20:52,390 INFO [SettingsFactory] Query language substitutions: {}
    14:20:52,390 INFO [SettingsFactory] JPA-QL strict compliance: enabled
    14:20:52,390 INFO [SettingsFactory] Second-level cache: enabled
    14:20:52,390 INFO [SettingsFactory] Query cache: disabled
    14:20:52,390 INFO [SettingsFactory] Cache provider: org.hibernate.cache.HashtableCacheProvider
    14:20:52,390 INFO [SettingsFactory] Optimize cache for minimal puts: disabled
    14:20:52,390 INFO [SettingsFactory] Cache region prefix: Test_jar,p
    14:20:52,390 INFO [SettingsFactory] Structured second-level cache entries: disabled
    14:20:52,390 INFO [SettingsFactory] Statistics: disabled
    14:20:52,390 INFO [SettingsFactory] Deleted entity synthetic identifier rollback: disabled
    14:20:52,390 INFO [SettingsFactory] Default entity-mode: pojo
    14:20:52,390 INFO [SettingsFactory] Named query checking : enabled
    14:20:52,390 INFO [SessionFactoryImpl] building session factory
    14:20:52,437 INFO [SessionFactoryObjectFactory] Factory name: persistence.units:jar=Test.jar,unitName=p
    14:20:52,437 INFO [NamingHelper] JNDI InitialContext properties:{java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory, java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces}
    14:20:52,437 INFO [SessionFactoryObjectFactory] Bound factory to JNDI name: persistence.units:jar=Test.jar,unitName=p
    14:20:52,437 WARN [SessionFactoryObjectFactory] InitialContext did not implement EventContext
    14:20:52,468 INFO [SchemaUpdate] Running hbm2ddl schema update
    14:20:52,468 INFO [SchemaUpdate] fetching database metadata
    14:20:52,531 INFO [SchemaUpdate] updating schema
    14:20:52,593 INFO [DatabaseMetadata] table not found: T3
    14:20:52,625 INFO [DatabaseMetadata] table not found: t2
    14:20:52,625 INFO [DatabaseMetadata] table not found: T3
    14:20:52,625 INFO [DatabaseMetadata] table not found: t2
    14:20:52,625 INFO [DatabaseMetadata] table not found: hibernate_sequence
    14:20:52,703 INFO [SchemaUpdate] schema update complete
    14:20:52,703 INFO [NamingHelper] JNDI InitialContext properties:{java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory, java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces}
    14:20:52,718 INFO [JmxKernelAbstraction] creating wrapper delegate for: org.jboss.ejb3.stateless.StatelessContainer
    14:20:52,718 INFO [JmxKernelAbstraction] installing MBean: jboss.j2ee:jar=Test.jar,name=T2Facade,service=EJB3 with dependencies:
    14:20:52,718 INFO [JmxKernelAbstraction] persistence.units:jar=Test.jar,unitName=p
    14:20:52,750 INFO [EJBContainer] STARTED EJB: ejb.T2Facade ejbName: T2Facade
    14:20:52,875 INFO [EJB3Deployer] Deployed: file:/C:/Program Files/jboss-4.2.0.GA/server/default/deploy/Test.jar/

    #271916 Reply

    maximuszen
    Member

    T3

    package ejb;

    import javax.persistence.Entity;
    import javax.persistence.GeneratedValue;
    import javax.persistence.GenerationType;
    import javax.persistence.Id;


    @Entity

    public class T3 {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    private String t;

    public T3(String t) {
    this.t = t;
    }

    public T3() {
    }

    public Long getId() {
    return this.id;
    }

    public void setId(Long id) {
    this.id = id;
    }

    public int hashCode() {
    return (this.id == null) ? 0 : this.id.hashCode();
    }

    public boolean equals(Object object) {
    if (object instanceof T3) {
    final T3 obj = (T3) object;
    return (this.id != null) ? this.id.equals(obj.id)
    : (obj.id == null);
    }
    return false;
    }

    public String getT() {
    return t;
    }

    public void setT(String t) {
    this.t = t;
    }

    }

    #271917 Reply

    maximuszen
    Member

    T2.java this was ejb3 reengineered from table t2

    package ejb;
    // default package

    import javax.persistence.Column;
    import javax.persistence.Entity;
    import javax.persistence.Id;
    import javax.persistence.Table;

    /**
    * T2 generated by MyEclipse Persistence Tools
    */

    @Entity

    @Table(name=”t2″
    ,schema=”public”
    , uniqueConstraints = { }
    )

    public class T2 implements java.io.Serializable {

    // Fields

    private Integer id;
    private String t;

    // Constructors

    /** default constructor */
    public T2() {
    }

    /** minimal constructor */
    public T2(Integer id) {
    this.id = id;
    }

    /** full constructor */
    public T2(Integer id, String t) {
    this.id = id;
    this.t = t;
    }

    // Property accessors
    @Id

    @Column(name=”id”, unique=true, nullable=false, insertable=true, updatable=true)

    public Integer getId() {
    return this.id;
    }

    public void setId(Integer id) {
    this.id = id;
    }

    @Column(name=”t”, unique=false, nullable=true, insertable=true, updatable=true)

    public String getT() {
    return this.t;
    }

    public void setT(String t) {
    this.t = t;
    }

    }

    #271918 Reply

    Riyad Kalla
    Member

    Notice the error, says the spec provider doesn’t implement something correctly, and I noticed you are using Hibernate. Try reconfiguring the project to use Toplink instead of Hibernate.

Viewing 11 posts - 1 through 11 (of 11 total)
Reply To: persistence.xml

You must be logged in to post in the forum log in