Skip to content

Instantly share code, notes, and snippets.

View thjanssen's full-sized avatar
🎓
Creating the best Java persistence courses for the @Persistence-Hub

Thorben Janssen thjanssen

🎓
Creating the best Java persistence courses for the @Persistence-Hub
View GitHub Profile
@Entity
public class Author implements Serializable
{
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id", updatable = false, nullable = false)
private Long id = null;
@Version
@Column(name = "version")
@thjanssen
thjanssen / Author.java
Created April 19, 2015 02:50
JBoss Forge - Speedup your enterprise development - Part II RESTful Webservices (http://www.thoughts-on-java.org/2013/09/rapid-application-development-with.html)
@Entity
@XmlRootElement
public class Author implements Serializable
{
...
@XmlTransient
public Set<Book> getBooks()
{
return this.books;
@thjanssen
thjanssen / AuthorEndpointTest.java
Created April 19, 2015 02:59
JBoss Forge - Speedup your enterprise development - Part III Integration Tests with Arquillian (http://www.thoughts-on-java.org/2013/10/jboss-forge-speedup-your-enterprise.html)
@RunWith(Arquillian.class)
public class AuthorEndpointTest
{
@Inject
private AuthorEndpoint authorendpoint;
@Deployment
public static JavaArchive createDeployment()
{
package blog.thoughts.on.java.jpa21.converter;
import java.awt.Color;
import javax.persistence.AttributeConverter;
import javax.persistence.Converter;
@Converter
public class ColorConverter implements AttributeConverter<Color, String> {
@thjanssen
thjanssen / delete.java
Last active April 26, 2017 08:07
Criteria Update/Delete - The easy way to implement bulk operations with JPA2.1 (http://www.thoughts-on-java.org/2013/10/criteria-updatedelete-easy-way-to.html)
@Stateless
@LocalBean
public class OrderManagement {
@PersistenceContext
private EntityManager em;
...
public void deleteOrder(Double amount) {
CriteriaBuilder cb = this.em.getCriteriaBuilder();
@NamedQueries(@NamedQuery(name = "Trip.findByVehicle", query = "SELECT trip FROM Trip trip WHERE vehicle=:vehicle"))
//
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.4-2
// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a>
// Any modifications to this file will be lost upon recompilation of the source schema.
// Generated on: 2014.01.13 at 07:38:24 PM CET
//
package blog.thoughts.on.java;
// define EJB client properties
final Properties props = new Properties();
// define SSL encryption
props.put("remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED",
"true");
props.put("remote.connection.default.connect.options.org.xnio.Options.SSL_STARTTLS",
"true");
// connection properties
props.put("remote.connections", "default");
props.put("remote.connection.default.host", "localhost");
@Entity
@Table(name = "purchaseOrder")
@NamedEntityGraph(name = "graph.Order.items",
attributeNodes = @NamedAttributeNode(value = "items", subgraph = "items"),
subgraphs = @NamedSubgraph(name = "items", attributeNodes = @NamedAttributeNode("product")))
public class Order implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id", updatable = false, nullable = false)
@thjanssen
thjanssen / Order.java
Created April 19, 2015 03:36
JPA 2.1 Entity Graph - Part 2: Define lazy/eager loading at runtime (http://www.thoughts-on-java.org/2014/04/jpa-21-entity-graph-part-2-define.html)
@Entity
@Table(name = "purchaseOrder")
@NamedEntityGraph(name = "graph.Order.items",
attributeNodes = @NamedAttributeNode(value = "items", subgraph = "items"),
subgraphs = @NamedSubgraph(name = "items", attributeNodes = @NamedAttributeNode("product")))
public class Order implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id", updatable = false, nullable = false)