This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Entity | |
public class CreditCard { | |
@Id | |
@GeneratedValue(strategy = GenerationType.IDENTITY) | |
private Integer id; | |
private String ccNumber; | |
private String name; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Converter | |
public class CryptoConverter implements AttributeConverter<String, String> { | |
private static final String ALGORITHM = "AES/ECB/PKCS5Padding"; | |
private static final byte[] KEY = "MySuperSecretKey".getBytes(); | |
@Override | |
public String convertToDatabaseColumn(String ccNumber) { | |
// do some encryption | |
Key key = new SecretKeySpec(KEY, "AES"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Singleton | |
@Remote(SingletonRemote.class) | |
public class DefaultLock implements SingletonRemote { | |
Logger logger = Logger.getLogger(DefaultLock.class.getName()); | |
private int counter = 0; | |
@Override | |
public void method1() { | |
this.logger.info("method1: " + counter); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Entity | |
@NamedEntityGraph(name = "graph.Order.items", | |
attributeNodes = @NamedAttributeNode("items")) | |
public class Order implements Serializable { | |
.... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Entity | |
public class Product implements Serializable | |
{ | |
@Id | |
@GeneratedValue(strategy = GenerationType.AUTO) | |
@Column(name = "id", updatable = false, nullable = false) | |
private Long id = null; | |
@Version | |
@Column(name = "version") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@SqlResultSetMapping( | |
name = "AuthorMapping", | |
entities = @EntityResult( | |
entityClass = Author.class, | |
fields = { | |
@FieldResult(name = "id", column = "authorId"), | |
@FieldResult(name = "firstName", column = "firstName"), | |
@FieldResult(name = "lastName", column = "lastName"), | |
@FieldResult(name = "version", column = "version")})) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@SqlResultSetMapping( | |
name = "BookValueMapping", | |
classes = @ConstructorResult( | |
targetClass = BookValue.class, | |
columns = { | |
@ColumnResult(name = "id", type = Long.class), | |
@ColumnResult(name = "title"), | |
@ColumnResult(name = "version", type = Long.class), | |
@ColumnResult(name = "authorName")})) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
List<BookValue> results = ((Session)this.em.getDelegate()).createSQLQuery("SELECT b.id, b.title, b.version, a.firstName || ' ' || a.lastName as authorName FROM Book b JOIN Author a ON b.author_id = a.id") | |
.addScalar("id", StandardBasicTypes.LONG).addScalar("title").addScalar("version", StandardBasicTypes.LONG).addScalar("authorName") | |
.setResultTransformer(new AliasToBeanResultTransformer(BookValue.class)).list(); | |
results.stream().forEach((book) -> { | |
System.out.println("Book: ID [" + book.getId() + "] title [" + book.getTitle() + "] authorName [" + book.getAuthorName() + "]"); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Converter(autoApply = true) | |
public class LocalDateAttributeConverter implements AttributeConverter<LocalDate, Date> { | |
@Override | |
public Date convertToDatabaseColumn(LocalDate locDate) { | |
return locDate == null ? null : Date.valueOf(locDate); | |
} | |
@Override | |
public LocalDate convertToEntityAttribute(Date sqlDate) { |