This file contains 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 | |
@DynamicUpdate | |
public class Book { | |
@Id | |
@GeneratedValue(strategy = GenerationType.AUTO) | |
@Column(name = "id", updatable = false, nullable = false) | |
private Long id; | |
@Version |
This file contains 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
@AnalyzerDef( | |
name = “textanalyzer”, | |
tokenizer = @TokenizerDef(factory = StandardTokenizerFactory.class), | |
filters = { | |
@TokenFilterDef(factory = LowerCaseFilterFactory.class), | |
@TokenFilterDef(factory = SnowballPorterFilterFactory.class, | |
params = { @Parameter(name = “language”, value = “English”) }) | |
} | |
) |
This file contains 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 Book { | |
@Id | |
@GeneratedValue(strategy = GenerationType.AUTO) | |
@Column(name = "id", updatable = false, nullable = false) | |
private Long id; | |
@Version | |
@Column(name = "version") | |
private int version; |
This file contains 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 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
@NamedStoredProcedureQuery( | |
name = "calculate", | |
procedureName = "calculate", | |
parameters = { | |
@StoredProcedureParameter(mode = ParameterMode.IN, type = Double.class, name = "x"), | |
@StoredProcedureParameter(mode = ParameterMode.IN, type = Double.class, name = "y"), | |
@StoredProcedureParameter(mode = ParameterMode.OUT, type = Double.class, name = "sum") | |
} | |
) |
This file contains 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
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> { |
This file contains 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
Book b = new Book(); | |
b.setTitle(“The Hound of the Baskervilles”); | |
b.setPublishingDate(LocalDate.of(1902, 4, 30)); | |
em.persist(b); |
This file contains 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) { |
This file contains 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
HashMap<String, Object> hints = new HashMap<>(); | |
hints.put("javax.persistence.query.timeout", 1000); | |
em.find(Author.class, 1L, hints); |
NewerOlder