#Error in implementing relationship b/w two entity

1 messages Β· Page 1 of 1 (latest)

twilit hull
#

`package com.masai.model;

@Entity
@NoArgsConstructor
@AllArgsConstructor
@Data
//@Table(name = "users")
public class User {

// {
// "email": "[email protected]",
// "firstName": "Saksham",
// "lastName": "Singh",
// "mobileNumber": "7987126495",
// "dateOfBirth": "1998-11-12",
// "username": "imsaksham9",
// "password": "sak@123"
// }

@Id
@Column(name = "email", unique = true)
@Email
private String email;

@NotNull
@NotBlank
@Pattern(regexp = "^[a-zA-Z]+$", message = "First name must not contain numbers or special characters")
private String firstName;

@NotNull
@NotBlank
@Pattern(regexp = "^[a-zA-Z]+$", message = "Last name must not contain numbers or special characters")
private String lastName;

@NotNull
@NotBlank
@Size(min = 3, max = 20)
@Pattern(regexp = "^[a-zA-Z0-9]+$", message = "Please input a valid username which contain lowercase character and length should be minimum 3 and maximum 20")
private String username;

@NotNull
@NotBlank
@Pattern(regexp = "^[0-9]{10}$", message = "Mobile number must have 10 digits")
private String mobileNumber;

@NotNull
@PastOrPresent
private LocalDate dateOfBirth;

@NotNull
@NotBlank
@Pattern(regexp = "^(?=.*[A-Za-z])(?=.*\\d)(?=.*[@$!%*#?&])[A-Za-z\\d@$!%*#?&]{6,12}$", message = "Password must be alphanumeric and must contain 6-12 characters having at least one special character, one upper case, one lowercase, and one digit.")
private String password;

@OneToMany(mappedBy = "user", cascade = CascadeType.ALL)
List<Email> emails = new ArrayList<>();

}
`

frank breachBOT
#

<@&987246584574140416> please have a look, thanks.

frank breachBOT
#

While you are waiting for getting help, here are some tips to improve your experience:

Code is much easier to read if posted with syntax highlighting and proper formatting.

If nobody is calling back, that usually means that your question was not well asked and hence nobody feels confident enough answering. Try to use your time to elaborate, provide details, context, more code, examples and maybe some screenshots. With enough info, someone knows the answer for sure.

Don't forget to close your thread using the command </help-thread close:1027500463647621170> when your question has been answered, thanks.

twilit hull
frank breachBOT
# twilit hull

I uploaded your attachments as gist. That way, they are easier to read for everyone, especially mobile users πŸ‘

inland oak
# twilit hull

You'll want to read the error message more carefully. User.emails is of type javax.validation.constraints.Email not com.masai.model.Email.

twilit hull
inland oak
# twilit hull Should I have to remove that validation?

You aren't validating. You're doing this:

List<javax.validation.constraints.Email> emails = new ArrayList<>();

But you want to do this:

List<com.masai.model.Email> emails = new ArrayList<>();

javax.validation.constaints.Email is an annotation. You even use it on your User.email field as an annotation:

@Email
private String email;

But then you use it as if it were a type on your User.emails.

twilit hull
#

Oh, I didn't read your previous reply carefully. Now I got it that's really a silly mistake from my side. Thank you so much for the help😊