Fix JPA validator warnings with explicit column names
Due to a bug in the JPA validator columns with camel case names are flagged as missing (probably due to the case-insensitive nature of SQL). This has been circumvented by assigning every column with a camel case name a new name with underscores. The inheritance strategy of the Contacts class has been changed to single table for performance reasons.
This commit is contained in:
		| @@ -3,17 +3,7 @@ package envoy.server.data; | ||||
| import java.util.Date; | ||||
| import java.util.Set; | ||||
|  | ||||
| import javax.persistence.CascadeType; | ||||
| import javax.persistence.Entity; | ||||
| import javax.persistence.FetchType; | ||||
| import javax.persistence.GeneratedValue; | ||||
| import javax.persistence.Id; | ||||
| import javax.persistence.Inheritance; | ||||
| import javax.persistence.InheritanceType; | ||||
| import javax.persistence.ManyToMany; | ||||
| import javax.persistence.Table; | ||||
| import javax.persistence.Temporal; | ||||
| import javax.persistence.TemporalType; | ||||
| import javax.persistence.*; | ||||
|  | ||||
| /** | ||||
|  * This class acts as a superclass for all contacts, being {@link User}s and | ||||
| @@ -29,7 +19,7 @@ import javax.persistence.TemporalType; | ||||
|  | ||||
| @Entity | ||||
| @Table(name = "contacts") | ||||
| @Inheritance(strategy = InheritanceType.JOINED) | ||||
| @Inheritance(strategy = InheritanceType.SINGLE_TABLE) | ||||
| public abstract class Contact { | ||||
|  | ||||
| 	@Id | ||||
| @@ -37,6 +27,7 @@ public abstract class Contact { | ||||
| 	protected long		id; | ||||
| 	protected String	name; | ||||
|  | ||||
| 	@Column(name = "creation_date") | ||||
| 	@Temporal(TemporalType.TIMESTAMP) | ||||
| 	private Date creationDate; | ||||
|  | ||||
|   | ||||
| @@ -5,7 +5,6 @@ import java.util.stream.Collectors; | ||||
| import javax.persistence.Entity; | ||||
| import javax.persistence.NamedQueries; | ||||
| import javax.persistence.NamedQuery; | ||||
| import javax.persistence.Table; | ||||
|  | ||||
| /** | ||||
|  * Represents a group inside the database. Referred to as "server group" as | ||||
| @@ -19,7 +18,6 @@ import javax.persistence.Table; | ||||
|  * @since Envoy Server Standalone v0.1-alpha | ||||
|  */ | ||||
| @Entity | ||||
| @Table(name = "groups") | ||||
| @NamedQueries({ | ||||
| 	@NamedQuery( | ||||
| 		name = Group.findByName, | ||||
| @@ -46,17 +44,11 @@ public class Group extends Contact { | ||||
| 	 */ | ||||
| 	public static final String findPendingGroups = "Group.findPendingGroups"; | ||||
|  | ||||
| 	/** | ||||
| 	 * {@inheritDoc} | ||||
| 	 */ | ||||
| 	@Override | ||||
| 	public envoy.data.Group toCommon() { | ||||
| 		return new envoy.data.Group(id, name, contacts.parallelStream().map(User.class::cast).map(User::toFlatCommon).collect(Collectors.toSet())); | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * {@inheritDoc} | ||||
| 	 */ | ||||
| 	@Override | ||||
| 	protected envoy.data.Group toFlatCommon() { return toCommon(); } | ||||
| } | ||||
|   | ||||
| @@ -3,10 +3,7 @@ package envoy.server.data; | ||||
| import java.util.Date; | ||||
| import java.util.Map; | ||||
|  | ||||
| import javax.persistence.ElementCollection; | ||||
| import javax.persistence.Entity; | ||||
| import javax.persistence.Temporal; | ||||
| import javax.persistence.TemporalType; | ||||
| import javax.persistence.*; | ||||
|  | ||||
| import envoy.data.MessageBuilder; | ||||
|  | ||||
| @@ -24,6 +21,7 @@ public class GroupMessage extends Message { | ||||
| 	@ElementCollection | ||||
| 	private Map<Long, envoy.data.Message.MessageStatus> memberMessageStatus; | ||||
|  | ||||
| 	@Column(name = "last_status_change_date") | ||||
| 	@Temporal(TemporalType.TIMESTAMP) | ||||
| 	protected Date lastStatusChangeDate; | ||||
|  | ||||
| @@ -64,7 +62,6 @@ public class GroupMessage extends Message { | ||||
| 			.setForwarded(forwarded) | ||||
| 			.setStatus(status) | ||||
| 			.setText(text) | ||||
| 			// .setAttachment(attachment) TODO make this work | ||||
| 			.buildGroupMessage((envoy.data.Group) recipient.toCommon(), memberMessageStatus); | ||||
| 		groupMessage.setReceivedDate(receivedDate); | ||||
| 		groupMessage.setReadDate(readDate); | ||||
|   | ||||
| @@ -49,12 +49,15 @@ public class Message { | ||||
| 	@JoinColumn | ||||
| 	protected Contact recipient; | ||||
|  | ||||
| 	@Column(name = "creation_date") | ||||
| 	@Temporal(TemporalType.TIMESTAMP) | ||||
| 	protected Date creationDate; | ||||
|  | ||||
| 	@Column(name = "received_date") | ||||
| 	@Temporal(TemporalType.TIMESTAMP) | ||||
| 	protected Date receivedDate; | ||||
|  | ||||
| 	@Column(name = "read_date") | ||||
| 	@Temporal(TemporalType.TIMESTAMP) | ||||
| 	protected Date readDate; | ||||
|  | ||||
| @@ -88,7 +91,7 @@ public class Message { | ||||
| 		sender			= persistenceManager.getUserByID(message.getSenderID()); | ||||
| 		recipient		= persistenceManager.getContactByID(message.getRecipientID()); | ||||
| 		forwarded		= message.isForwarded(); | ||||
| 		// TODO: attachment = message.getAttachment().toByteArray();DOES NOT WORK YET | ||||
| 		// TODO: Attachment | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| @@ -104,7 +107,6 @@ public class Message { | ||||
| 			.setDate(creationDate) | ||||
| 			.setStatus(status) | ||||
| 			.setForwarded(forwarded) | ||||
| 			// .setAttachment(attachment) TODO make this work | ||||
| 			.build(); | ||||
| 		message.setReceivedDate(receivedDate); | ||||
| 		message.setReadDate(readDate); | ||||
|   | ||||
| @@ -22,7 +22,6 @@ import envoy.data.User.UserStatus; | ||||
|  * @since Envoy Server Standalone v0.1-alpha | ||||
|  */ | ||||
| @Entity | ||||
| @Table(name = "users") | ||||
| @NamedQueries({ | ||||
| 	@NamedQuery( | ||||
| 		name = User.findByName, | ||||
| @@ -63,8 +62,10 @@ public class User extends Contact { | ||||
| 	 */ | ||||
| 	public static final String searchByName = "User.searchByName"; | ||||
|  | ||||
| 	@Column(name = "password_hash") | ||||
| 	private byte[] passwordHash; | ||||
|  | ||||
| 	@Column(name = "last_seen") | ||||
| 	@Temporal(TemporalType.TIMESTAMP) | ||||
| 	private Date lastSeen; | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user