Last active
August 16, 2016 17:24
-
-
Save thjanssen/444f1a555110fb5f83c5de377733518f to your computer and use it in GitHub Desktop.
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 Book { | |
... | |
@Column | |
private LocalDate publishingDate; | |
... | |
public Optional getPublishingDate() { | |
return Optional.ofNullable(publishingDate); | |
} | |
public void setPublishingDate(LocalDate publishingDate) { | |
this.publishingDate = publishingDate; | |
} | |
} |
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
Session session = em.unwrap(Session.class); | |
Optional<Book> book = session.byId(Book.class).loadOptional(1L); | |
if (book.isPresent()) { | |
log.info(“Found book with id [“+book.get().getId()+”] and title [“+book.get().getTitle()+”].”); | |
} else { | |
log.info(“Book doesn’t exist.”); | |
} |
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
javax.persistence.PersistenceException: [PersistenceUnit: my-persistence-unit] Unable to build Hibernate SessionFactory | |
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.persistenceException(EntityManagerFactoryBuilderImpl.java:951) | |
... | |
Caused by: org.hibernate.MappingException: Could not determine type for: java.util.Optional, at table: Book, for columns: [org.hibernate.mapping.Column(publishingDate)] | |
at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:454) | |
at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:421) | |
at org.hibernate.mapping.Property.isValid(Property.java:226) | |
at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:595) | |
at org.hibernate.mapping.RootClass.validate(RootClass.java:265) | |
at org.hibernate.boot.internal.MetadataImpl.validate(MetadataImpl.java:329) | |
at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:489) | |
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:878) | |
... 28 more |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment