javantura v2 - morphia - painfree jpa for mongodb - philipp krenn
Upload: hujak-hrvatska-udruga-java-korisnika-croatian-java-user-association
Post on 05-Jul-2015
531 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
![Page 1: Javantura v2 - Morphia - painfree JPA for MongoDB - Philipp Krenn](https://reader034.vdocuments.mx/reader034/viewer/2022052316/559867631a28abc32f8b4866/html5/thumbnails/1.jpg)
MorphiaJPA for MongoDB
![Page 3: Javantura v2 - Morphia - painfree JPA for MongoDB - Philipp Krenn](https://reader034.vdocuments.mx/reader034/viewer/2022052316/559867631a28abc32f8b4866/html5/thumbnails/3.jpg)
Who uses
JPA?
![Page 4: Javantura v2 - Morphia - painfree JPA for MongoDB - Philipp Krenn](https://reader034.vdocuments.mx/reader034/viewer/2022052316/559867631a28abc32f8b4866/html5/thumbnails/4.jpg)
Who uses
MongoDB?
![Page 5: Javantura v2 - Morphia - painfree JPA for MongoDB - Philipp Krenn](https://reader034.vdocuments.mx/reader034/viewer/2022052316/559867631a28abc32f8b4866/html5/thumbnails/5.jpg)
Who uses
Morphia?
![Page 6: Javantura v2 - Morphia - painfree JPA for MongoDB - Philipp Krenn](https://reader034.vdocuments.mx/reader034/viewer/2022052316/559867631a28abc32f8b4866/html5/thumbnails/6.jpg)
Like JPA for MongoDB
...but better
![Page 7: Javantura v2 - Morphia - painfree JPA for MongoDB - Philipp Krenn](https://reader034.vdocuments.mx/reader034/viewer/2022052316/559867631a28abc32f8b4866/html5/thumbnails/7.jpg)
@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;
![Page 8: Javantura v2 - Morphia - painfree JPA for MongoDB - Philipp Krenn](https://reader034.vdocuments.mx/reader034/viewer/2022052316/559867631a28abc32f8b4866/html5/thumbnails/8.jpg)
![Page 9: Javantura v2 - Morphia - painfree JPA for MongoDB - Philipp Krenn](https://reader034.vdocuments.mx/reader034/viewer/2022052316/559867631a28abc32f8b4866/html5/thumbnails/9.jpg)
Relations vs Objects
![Page 10: Javantura v2 - Morphia - painfree JPA for MongoDB - Philipp Krenn](https://reader034.vdocuments.mx/reader034/viewer/2022052316/559867631a28abc32f8b4866/html5/thumbnails/10.jpg)
MongoDB
![Page 11: Javantura v2 - Morphia - painfree JPA for MongoDB - Philipp Krenn](https://reader034.vdocuments.mx/reader034/viewer/2022052316/559867631a28abc32f8b4866/html5/thumbnails/11.jpg)
Table = CollectionSchemaless
Row = DocumentJSON
![Page 12: Javantura v2 - Morphia - painfree JPA for MongoDB - Philipp Krenn](https://reader034.vdocuments.mx/reader034/viewer/2022052316/559867631a28abc32f8b4866/html5/thumbnails/12.jpg)
{ "name": "Philipp", "isAlive": true, "age": 30, "height_cm": 181.5, "address": { "city": "Vienna", "postalCode": "1190" }, "phoneNumbers": [ { "type": "mobile", "number": "+43 123 4567890" } ], "children": []}
![Page 13: Javantura v2 - Morphia - painfree JPA for MongoDB - Philipp Krenn](https://reader034.vdocuments.mx/reader034/viewer/2022052316/559867631a28abc32f8b4866/html5/thumbnails/13.jpg)
Morphia
![Page 14: Javantura v2 - Morphia - painfree JPA for MongoDB - Philipp Krenn](https://reader034.vdocuments.mx/reader034/viewer/2022052316/559867631a28abc32f8b4866/html5/thumbnails/14.jpg)
Object-Document Mapping
POJO + AnnotationsObject-Relational Mapping
![Page 15: Javantura v2 - Morphia - painfree JPA for MongoDB - Philipp Krenn](https://reader034.vdocuments.mx/reader034/viewer/2022052316/559867631a28abc32f8b4866/html5/thumbnails/15.jpg)
FeaturesLightweight
Type safe & preserving
![Page 16: Javantura v2 - Morphia - painfree JPA for MongoDB - Philipp Krenn](https://reader034.vdocuments.mx/reader034/viewer/2022052316/559867631a28abc32f8b4866/html5/thumbnails/16.jpg)
Required librarieshttps://github.com/mongodb/
mongo-java-driver (2.12.4)+
https://github.com/mongodb/morphia (0.108)
![Page 17: Javantura v2 - Morphia - painfree JPA for MongoDB - Philipp Krenn](https://reader034.vdocuments.mx/reader034/viewer/2022052316/559867631a28abc32f8b4866/html5/thumbnails/17.jpg)
Show me some codehttps://github.com/xeraa/
morphia-demo
![Page 18: Javantura v2 - Morphia - painfree JPA for MongoDB - Philipp Krenn](https://reader034.vdocuments.mx/reader034/viewer/2022052316/559867631a28abc32f8b4866/html5/thumbnails/18.jpg)
TODO: final class diagram
![Page 19: Javantura v2 - Morphia - painfree JPA for MongoDB - Philipp Krenn](https://reader034.vdocuments.mx/reader034/viewer/2022052316/559867631a28abc32f8b4866/html5/thumbnails/19.jpg)
Annotations
![Page 20: Javantura v2 - Morphia - painfree JPA for MongoDB - Philipp Krenn](https://reader034.vdocuments.mx/reader034/viewer/2022052316/559867631a28abc32f8b4866/html5/thumbnails/20.jpg)
@Entity
@Entity( value = "company", noClassnameStored = true)public class CompanyEntity {
Tip: Avoid dashes in the collection name
![Page 21: Javantura v2 - Morphia - painfree JPA for MongoDB - Philipp Krenn](https://reader034.vdocuments.mx/reader034/viewer/2022052316/559867631a28abc32f8b4866/html5/thumbnails/21.jpg)
Queries
![Page 22: Javantura v2 - Morphia - painfree JPA for MongoDB - Philipp Krenn](https://reader034.vdocuments.mx/reader034/viewer/2022052316/559867631a28abc32f8b4866/html5/thumbnails/22.jpg)
![Page 23: Javantura v2 - Morphia - painfree JPA for MongoDB - Philipp Krenn](https://reader034.vdocuments.mx/reader034/viewer/2022052316/559867631a28abc32f8b4866/html5/thumbnails/23.jpg)
Patterns
![Page 24: Javantura v2 - Morphia - painfree JPA for MongoDB - Philipp Krenn](https://reader034.vdocuments.mx/reader034/viewer/2022052316/559867631a28abc32f8b4866/html5/thumbnails/24.jpg)
Base Class
![Page 25: Javantura v2 - Morphia - painfree JPA for MongoDB - Philipp Krenn](https://reader034.vdocuments.mx/reader034/viewer/2022052316/559867631a28abc32f8b4866/html5/thumbnails/25.jpg)
Converters
![Page 26: Javantura v2 - Morphia - painfree JPA for MongoDB - Philipp Krenn](https://reader034.vdocuments.mx/reader034/viewer/2022052316/559867631a28abc32f8b4866/html5/thumbnails/26.jpg)
Auto Increments
![Page 27: Javantura v2 - Morphia - painfree JPA for MongoDB - Philipp Krenn](https://reader034.vdocuments.mx/reader034/viewer/2022052316/559867631a28abc32f8b4866/html5/thumbnails/27.jpg)
Encryption
![Page 28: Javantura v2 - Morphia - painfree JPA for MongoDB - Philipp Krenn](https://reader034.vdocuments.mx/reader034/viewer/2022052316/559867631a28abc32f8b4866/html5/thumbnails/28.jpg)
![Page 29: Javantura v2 - Morphia - painfree JPA for MongoDB - Philipp Krenn](https://reader034.vdocuments.mx/reader034/viewer/2022052316/559867631a28abc32f8b4866/html5/thumbnails/29.jpg)
Future
![Page 30: Javantura v2 - Morphia - painfree JPA for MongoDB - Philipp Krenn](https://reader034.vdocuments.mx/reader034/viewer/2022052316/559867631a28abc32f8b4866/html5/thumbnails/30.jpg)