javantura v2 - morphia - painfree jpa for mongodb - philipp krenn
Upload: hujak-hrvatska-udruga-java-korisnika-croatian-java-user-association
Post on 05-Jul-2015
528 views
DESCRIPTION
Morphia is MongoDB’s JPA-like Object-Document Mapping (ODM). However, there is no object-relational impedence mismatch since documents fit the concept of object-orientation much better — as this talk shows. On a practical level we will take a look at the available annotations and how to map your objects as well as how to easily query data in MongoDB. The talk concludes with some tips and the lesson we’ve learned from using Morphia in production for three years.TRANSCRIPT
MorphiaJPA for MongoDB
Philipp Krenn@xeraa
Who uses
JPA?
Who uses
MongoDB?
Who uses
Morphia?
Like JPA for MongoDB
...but better
@OneToMany(mappedBy = "destCustomerId")@ManyToMany@Fetch(FetchMode.SUBSELECT)@JoinTable(name = "customer_dealer_map", joinColumns = { @JoinColumn(name = "customer_id", referencedColumnName = "id")}, inverseJoinColumns = { @JoinColumn(name = "dealer_id", referencedColumnName = "id")})private Collection<Client> dealers;
Relations vs Objects
MongoDB
Table = CollectionSchemaless
Row = DocumentJSON
{ "name": "Philipp", "isAlive": true, "age": 30, "height_cm": 181.5, "address": { "city": "Vienna", "postalCode": "1190" }, "phoneNumbers": [ { "type": "mobile", "number": "+43 123 4567890" } ], "children": []}
Morphia
Object-Document Mapping
POJO + AnnotationsObject-Relational Mapping
FeaturesLightweight
Type safe & preserving
Required librarieshttps://github.com/mongodb/
mongo-java-driver (2.12.4)+
https://github.com/mongodb/morphia (0.108)
Show me some codehttps://github.com/xeraa/
morphia-demo
TODO: final class diagram
Annotations
@Entity
@Entity( value = "company", noClassnameStored = true)public class CompanyEntity {
Tip: Avoid dashes in the collection name
Queries
Patterns
Base Class
Converters
Auto Increments
Encryption
Future