Tag meta geo histo models
Added models for Tag, Metadata, Geolocation and Histogram. Not sure if the relations between models are excatly how we want them, but feel free to request improvements and changes. xoxo
Merge request reports
Activity
- Resolved by Eirik Steira
- Resolved by Eirik Steira
- Resolved by Eirik Steira
- src/main/java/NTNU/IDATT1002/models/Tag.java 0 → 100644
14 15 @Entity 16 @Table(name = "Tag") 17 public class Tag { 18 19 /* 20 Defines the tag-id, this cannot be blank 21 */ 22 23 24 @Id @NotBlank(message = "Tag-Id may not be blank") 25 @GeneratedValue(strategy = GenerationType.AUTO) 26 private int tagId; 27 28 @Id @NotBlank(message = "Image-Id may not be blank") 29 private int imageId; changed this line in version 3 of the diff
This is complex stuff and you have done a good job defining the relationships. However, there are some minor flaws when in comes to which column a foreign key should join on which is why I left some comments.
Other than that there is a couple of things that should be looked into:
- The code fails to run once the entity classes are registered (point 3). You can test the implementation by adding this to App.main() and then compile and run it.
EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory("ImageApplication"); EntityManager entityManager = entityManagerFactory.createEntityManager();
- Proper JavaDoc. The JavaDoc should be on the form /**
*/ and no spacing preceding what is to be documented.
Read more here: https://www.oracle.com/technetwork/java/javase/documentation/index-137868.html
- Add entity classes to src/main/java/resources/META-INF/persistence.xml and to the test file src/test/java/resources/META-INF/persistence.xml to register the entities and create the tables.
Edited by Eirik Steiraadded 2 commits
20 private int metadataId; 21 22 /** 23 * One to one relation joining imageId 24 * on image_id column in image 25 */ 26 27 @OneToOne 28 @JoinColumn(name = "image_id") 29 private Image image; 30 31 @NotBlank (message = "GeolocationId may not be blank") 32 private int geoLocationId; 33 34 @NotBlank (message = "HistogramId may not be blank") 35 private int histogramId; Since these are declared and the metadata model should know about the geolocation and histogram, the relationship should be declared here as well.
Also, to keep the code as standardized as possible, we try to use a primitive wrapper type for id fields, ie
Long
instead oflong
. This goes for all id fields :)
mentioned in commit b323c9d3