Skip to main content

Home/ SoftwareEngineering/ Group items tagged jpa

Rss Feed Group items tagged

kuni katsuya

JPA Reference Guide - JBoss AS 7.0 - Project Documentation Editor - 0 views

  • Persistence unit properties
  • Should be hibernate3-bundled if Hibernate 3 jars are in the application archive (adapterModule and adapterClass will automatically be set for hibernate3-bundled).
  • org.jboss.as.jpa.hibernate:3 (Hibernate 3 integration classes)
  • ...14 more annotations...
  • jboss.as.jpa.adapterModule
  • jboss.as.jpa.adapterClass
  • org.jboss.as.jpa.hibernate3.HibernatePersistenceProviderAdaptor
  • Working with other persistence providers
  • A project to build integration for persistence providers like EclipseLink, is here.
  • Troubleshooting
  • “org.jboss.as.jpa” logging can be enabled to get the following information: INFO - when persistence.xml has been parsed, starting of persistence unit service (per deployed persistence.xml), stopping of persistence unit service DEBUG - informs about entity managers being injected, creating/reusing transaction scoped entity manager for active transaction TRACE - shows how long each entity manager operation took in milliseconds, application searches for a persistence unit, parsing of persistence.xml
  • To enable TRACE, open the as/standalone/configuration/standalone.xml (or as/domain/configuration/domain.xml) file. Search for <subsystem xmlns="urn:jboss:domain:logging:1.0"> and add the org.jboss.as.jpa category
  • Packaging the Hibernate 3.5 or greater 3.x JPA persistence provider with your application
  • jboss.as.jpa.providerModule needs to be set to hibernate3-bundled.
  • <property name="jboss.as.jpa.providerModule" value="hibernate3-bundled" />
  • Sharing the Hibernate 3.5 or greater JPA persistence provider between multiple applications
  • Applications can share the same Hibernate3 (for Hibernate 3.5 or greater) persistence provider by manually creating an org.hibernate:3 module (in the AS/modules folder). Steps to create the Hibernate3 module:
  • <property name="jboss.as.jpa.providerModule" value="org.hibernate:3" />
kuni katsuya

Java Persistence/Relationships - Wikibooks, open books for an open world - 0 views

  • Map Key Columns (JPA 2.0)
  • Nested Collections, Maps and Matrices
  • List of Lists
  • ...58 more annotations...
  • Map of Maps,
  • Map of Lists
  • JPA does not support nested collection relationships
  • One solution is to create an object that wraps the nested collection.
  • Map<String, List<Project>>
  • Example nested collection model (original)
  • Example nested collection model (modified)
  • Map<String, ProjectType>
  • @MapKey(name="type")
  • mappedBy="employee"
  • employee
  • type;
  • List<Project>
  • ProjectType
    • kuni katsuya
       
      ProjectType wraps the original map value type List>
  • Maps J
  • JPA allows a Map to be used for any collection mapping including, OneToMany, ManyToMany and ElementCollection
  • @MapKey annotation
  • used to define a map relationship
  • @MapKey(name="type")
  • Map<String, PhoneNumber>
  • type;
  • mappedBy="owner"
  • owner
  • Map Key Columns (JPA 2.0)
  • Map Key Columns (JPA 2.0)
  • JPA 2.0 allows for a Map where the key is not part of the target object to be persisted. The Map key can be any of the following:
  • A Basic value, stored in the target's table or join table.
  • An Embedded object, stored in the target's table or join table.
  • A foreign key to another Entity, stored in the target's table or join table.
  • if the value is a Basic but the key is an Entity a
  • ElementCollection
  • mapping is used.
  • if the key is a Basic but the value is an Entity a
  • OneToMany
  • mapping is still used
  • a three way join table, can be mapped using a
  • ManyToMany with a MapKeyJoinColumn for the third foreign key
  • @MapKeyJoinColumn
  • used to define a map relationship where the
  • key is an Entity value
  • can also be used with this for composite foreign keys
  • @MapKeyClass
  • can be used when the key is an Embeddable
  • if generics are not used
  • @MapKeyColumn
  • Map<String, Phone>
  • mappedBy="owner"
  • owner
  • @MapKeyJoinColumn
  • PHONE_TYPE_ID
  • PHONE_TYPE_ID
  • Map<PhoneType, Phone>
  • mappedBy="owner"
  • owner
  • @MapKeyClass(PhoneType.class)
  • @Embeddable
  • PhoneType
  • Map<PhoneType, Phone>
  •  
    "Map Key Columns (JPA 2.0)"
kuni katsuya

12 Tips On JPA Domain Modelling - With Existing Database - Thinking In Structs Not Obje... - 0 views

  • think in structs. Try to as frictionless as possible export/generate the JPA-entities from the existing database
  • Implement a very thin facade / transaction boundary
  • @Stateless Bean (EJB 3)
  • ...10 more annotations...
  • If the JPA entities still do not look right, try to apply some JPA tricks like mapping a JPA-entity to several tables, or even map JPA-entities to DB-views, to improve the situation
  • Rename the classes into some more meaningful. The attribute, class names are in general everything but not fluent
  • Junit. Purpose: JPA mapping verification
  • Thinking In Structs Not Objects
  • 12 Tips On JPA Domain Modelling
  • - With Existing Database -
    • kuni katsuya
       
      strategy when constrained by baggage of *legacy database* schema, NOT for a green fields project!
  • Execute the "Unit" tests after every change
  • even better get rid of them
  • domain objects are
  • semi-objectoriented
kuni katsuya

JBoss Developer Framework - 0 views

  • jta-crash-rec Crash Recovery, JTA Uses Java Transaction API and JBoss Transactions to demonstrate recovery of a crashed transaction
  • jts-distributed-crash-rec JTS Demonstrates recovery of distributed crashed components
  • cdi-injection CDI Demonstrates the use of CDI 1.0 Injection and Qualifiers with JSF as the front-end client.
  • ...13 more annotations...
  • bean-validation JPA, Bean Validation Shows how to use Arquillian to test Bean Validation
  • ejb-security Security, EJB Shows how to use Java EE Declarative Security to Control Access to EJB 3
  • payment-cdi-event CDI Demonstrates how to use CDI 1.0 Events
  • richfaces-validation RichFaces Demonstrates RichFaces and bean validation
  • ejb-in-war JSF, WAR, EJB Packages an EJB JAR in a WAR
  • greeter EJB, JPA, JSF, JTA, CDI Demonstrates the use of CDI 1.0, JPA 2.0, JTA 1.1, EJB 3.1 and JSF 2.0
  • helloworld-mdb EJB, MDB, JMS Demonstrates the use of JMS 1.1 and EJB 3.1 Message-Driven Bean
  • helloworld-rs JAX-RS, CDI Demonstrates the use of CDI 1.0 and JAX-RS
  • kitchensink BV, EJB, JAX-RS, JPA, JPA, JSF, CDI
  • servlet-async CDI, EJB, Servlet Demonstrates CDI, plus asynchronous Servlets and EJBs
  • servlet-security Security, Servlet Demonstrates how to use Java EE declarative security to control access to Servlet 3
  • shopping-cart EJB Demonstrates a stateful session bean
  • tasks Arquillian, JPA Demonstrates testing JPA using Arquillian
kuni katsuya

A proper way for JPA entities instantiation « Paul Szulc's Blog - 0 views

  • A proper way for JPA entities instantiation
  • creating the entities I would like to focus in this post
  • JPA2.0 entities
  • ...31 more annotations...
  • UserService
  • UserDao
  • FacebookWS
  • User u
  • UserService uses UserDAO and FacebookWS
  • but don’t know how those dependencies are instantiated
  • And you shouldn’t really care, all that is important is that UserService depends on dao and webservice object.
  • BDD template given-when-then) tests are easy to read
  • @Entity
  • public class User
  • calling new User(“someName”,”somePassowrd”, “someOtherName”, “someOtherPassword”) becomes hardly readable and maintainable
  • code duplication
  • Maintaining this code would turn into a nightmare in no time
  • running the code above will throw an exception by the JPA provider,
  • since not-nullable password field was never set.
  • Joshua Blooch gives fine example of builder pattern.
  • Instead of making the desired object directly, the client calls a constructor (or static factory) with all of the required parameters and gets a builder object. Then the client calls setter-like methods on the builder object to set each optional parameter of interest. Finally, the client calls a parameterless build method to generate the object, which is immutable. The builder is a static member class of the class it builds.
  • Coffee
  • public static class Builder
  • Builder(CoffeeType type, int cupSize)
  • Builder withMilk()
  • Coffee build()
  • Coffee(this)
  • private Coffee(Builder builder)
  • Coffee coffee = new Coffee.Builder(CoffeeType.Expresso, 3).withMilk().build();2}
  • especially if most of those parameters are optional.
  • For all entity attributes I create private fields
  • those that are obligatory become parameters for the public constructor
  • parameter-less constructor, I create one, but I give him
  • protected access level
  • protected
kuni katsuya

Pro JPA 2: Mastering the Java™ Persistence API > Advanced Topics > SQL Querie... - 0 views

  • queries are also known as native queries
  • SQL Queries
  • reasons why a developer using JP QL might want to integrate SQL queries into their application
  • ...32 more annotations...
  • JPA 2.0, still contains only a subset of the features supported by many database vendors
  • features not supported in JP QL.
  • performance required by an application is to replace the JP QL query with a hand-optimized SQL version. This may be a simple restructuring of the query that the persistence provider was generating, or it may be a vendor-specific version that leverages query hints and features specific to a particular database.
  • recommend avoiding SQL initially if possible and then introducing it only when necessary
  • benefits of SQL query support is that it uses the same Query interface used for JP QL queries. With some small exceptions that will be described later, all the Query interface operations discussed in previous chapters apply equally to both JP QL and SQL queries.
  • keep application code consistent because it needs to concern itself only with the EntityManager and Query interfaces.
  • An unfortunate result of adding the TypedQuery interface in JPA 2.0 is that the createNativeQuery() method was already defined in JPA 1.0 to accept a SQL string and a result class and return an untyped Query interface
  • consequence is that when the createNativeQuery() method is called with a result class argument one might mistakenly think it will produce a TypedQuery, like createQuery() and createNamedQuery() do when a result class is passed in.
  • @NamedNativeQuery
  • resultClass=Employee.class
  • The fact that the named query was defined using SQL instead of JP QL is not important to the caller
  • SQL Result Set Mapping
  • JPA provides SQL result set mappings to handle these scenarios
  • A SQL result set mapping is defined using the @SqlResultSetMapping annotation. It may be placed on an entity class and consists of a name (unique within the persistence unit) and one or more entity and column mappings.
  • entities=@EntityResult(entityClass=Employee.class)
  • @SqlResultSetMapping
  • Multiple Result Mappings
  • A query may return more than one entity at a time
  • The SQL result set mapping to return both the Employee and Address entities out of this query
  • emp_id, name, salary, manager_id, dept_id
  • address_id, id, street, city, state, zip
  • order in which the entities are listed is not important
  • ntities={@EntityResult(entityClass=Employee.class), @EntityResult(entityClass=Address.class)}
  • expected result type and therefore received an instance of TypedQuery that is bound to the expected type. By qualifying the result type in this way, the getResultList() and getSingleResult() methods return the correct types without the need for casting.
  • Defining a Class for Use in a Constructor Expression
  • public EmpMenu(String employeeName, String departmentName)
  • List<EmpMenu>
  • NEW example.EmpMenu(" + "e.name, e.department.name)
  • EmpMenu.class
  • createNamedQuery() can return a TypedQuery whereas the createNativeQuery() method returns an untyped Query
  • List<Employee>
  • createNamedQuery("orgStructureReportingTo", Employee.class)
kuni katsuya

schuchert - JPA Tutorial 4 - Inheritance and Polymorphic Queries - 0 views

  • JPA Tutorial 4 - Inheritance and Polymorphic Queries
  • Books and Dvd's, both of which inherit from Resource
  • When we search for a Resource we might get back Books, Dvd's, or both
  • ...12 more annotations...
  • queries polymorphic
  • Introduce the Resource class
  • new type, Dvd
  • What happens when you perform a query on a type that has subclasses?
  • It turns out support for inheritance in queries (as well as JPA) is built in
  • do not actually need to do anything other than have one entity inherit from another entity to get everything to work
  • book entity inherit from the Resource entity
  • Introduce a new entity type called Resource
  • Change the BookDao to be a ResourceDao
  • Update the methods returning Book and have them instead return Resource
  • Update all references to Book and replace them with Resource
  • Change the bookId to resourceId
kuni katsuya

JPA implementation patterns: Retrieving entities | Xebia Blog - 0 views

  • JPA implementation patterns: Retrieving entities
  • two ways to retrieve an entity with JPA:
  • EntityManager.find
  • ...2 more annotations...
  • Query object that can then be executed to return a list of entities or a single entity.
  • Keeping the query and the code that sets these parameters together makes them both easier to understand
kuni katsuya

JPA/Hibernate Ternary Association « Fulvio Di Marco: just a personal code not... - 0 views

  • JPA/Hibernate Ternary Association
  •  
    "JPA/Hibernate Ternary Association"
kuni katsuya

Chapter 3. Project Setup - 0 views

  • Using Maven archetypes
  • GraniteDS/Tide/CDI/JPA: graniteds-tide-cdi-jpa
  • GraniteDS/Tide/Seam 2/JPA/Hibernate: graniteds-tide-seam-jpa-hibernate
  • ...3 more annotations...
  • Maven 3 is highly recommended but Maven 2.2 should also work
  • CDI archetype defines an embedded GlassFish run configuration
  • mvn embedded-glassfish:run
kuni katsuya

The JPA 2 Enhancements Every Java Developer Should Know - Developer.com - 0 views

  • JPA 2 Enhancements Every Java Developer Should Know
  • JPA 2 also introduced a second layer of cache, which is shared across various persistence contexts and can be accessed using the EntityManagerFactory
  • Cache cache = emf.getCache();
  • ...4 more annotations...
  • Enhancements in EntityManagerFactory Interface
  • Enhancements in EntityManager Interface
  • detach
  • getEntityManagerFactory
kuni katsuya

Getting Started Developing Applications Guide - JBoss AS 7.1 - Project Documentation Ed... - 0 views

  • CDI + JPA + EJB + JTA + JSF: Login quickstart
  • displayed using JSF views, business logic is encapsulated in CDI beans, information is persisted using JPA, and transactions can be controlled manually or using EJB
  • Deploying the Login example using Eclipse
  • ...6 more annotations...
  • deploy the example by right clicking on the jboss-as-login project, and choosing Run As -> Run On Server
  • src/main/webapp directory
  • beans.xml and face-config.xml tell JBoss AS to enable CDI and JSF for the application
  • don't need a web.xml
  • src/main/resources
  • persistence.xml, which sets up JPA, and import.sql which Hibernate, the JPA provider in JBoss AS, will use to load the initial users into the application when the application starts
kuni katsuya

DataNucleus Access Platform - JPA Inheritance - 0 views

  • DataNucleus AccessPlatform 3.1 Documentation
  • JPA : Inheritance Strategies
  • JOINED
  • ...2 more annotations...
  • "JOINED" strategy
  • each entity in the inheritance hierarchy has its own table and that the table of each class only contains columns for that class
kuni katsuya

Java Persistence/Advanced Topics - Wikibooks, open books for an open world - 0 views

  • Events
  • hook into a system that allows the execution of some code when the event occurs
  • JPA defines several events for the persistent
  • ...37 more annotations...
  • life-cycle
  • of Entity objects
  • JPA defines the following events:
  • PostLoad
  • PrePersist
  • PostPersist
  • PreUpdate
  • PostUpdate
  • PreRemove
  • PostRemove
  • after an Entity is loaded into the
  • persistence context
  • before the persist operation is invoked on an Entity
  • after a refresh operation.
  • before the remove operation is invoked on an Entity
  • cascade of a remove operation
  • during a flush or commit for orphanRemoval in JPA 2.0
  • after an instance is deleted from the database
  • occurs during a flush or commit operation
  • after the database DELETE has occurred
  • before the transaction is committed
  • after an instance is updated in the database
  • occurs during a flush or commit operation
  • after the database UPDATE has occurred
  • before the transaction is committed
  • before an instance is updated in the database
  • occurs during a flush or commit operation
  • after the database UPDATE has occurred
  • before the transaction is committed
  • after a new instance is persisted to the database
  • occurs during a flush or commit operation
  • after the database INSERT has occurred
  • before the transaction is committed
  • Id of the object should be assigned
  • merge for new instances
  • cascade of a persist operation
  • Id of the object may not have been assigned, and code be assigned by the event
kuni katsuya

JPA implementation patterns: Bidirectional assocations | Xebia Blog - 0 views

  • JPA implementation patterns: Bidirectional assocations
  • it gets interesting when we make this association bidirectional
  • But there is a catch!
  • ...2 more annotations...
  • if you run them within one transaction like the code below does, you will find that the item list while be empty:
  • to keep bidirectional associations in sync, JPA leaves more up to the developer.
kuni katsuya

Arquillian with NetBeans, GlassFish embedded, JPA and a MySQL Datasource - Java Code Geeks - 0 views

  • Arquillian with NetBeans, GlassFish embedded, JPA and a MySQL Datasource
  • Arquillian with NetBeans, GlassFish embedded, JPA and a MySQL Datasource
1 - 20 of 122 Next › Last »
Showing 20 items per page