0

It gives me the below error.

org.hibernate.MappingException: Could not determine type for: java.util.List, at table: user, for columns: [org.hibernate.mapping.Column(events)]

Here my Code

User.java:

import com.google.common.base.Objects;

import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

@Entity
public class User {

    @Id
    @NotNull
    @Size(max = 64)
    @Column(name = "id", nullable = false, updatable = false)
    private String id;

    @NotNull
    @Size(max = 64)
    @Column(name = "name", nullable = false)
    private String name;

    @NotNull
    @Size(max = 64)
    @Column(name = "firstname", nullable = false)
    private String firstname;

    @NotNull
    @Size(max = 64)
    @Column(name = "email", nullable = false)
    private String email;

    @NotNull
    @Size(max = 64)
    @Column(name = "password", nullable = false)
    private String password;


    private List<Events> events;

    public User() {
    }

    public User(String id, String name, String firstname, String email, String password) {
        super();
        this.id = id;
        this.name = name;
        this.firstname = firstname;
        this.email = email;
        this.password = password;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getId() {
        return id;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getFirstname() {
        return firstname;
    }

    public void setFirstname(String firstname) {
        this.firstname = firstname;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public List<Events> getEvents() {
        return events;
    }

    public void setEvents(List<Events> events) {
        this.events = events;
    }

    @Override
    public String toString() {
        return Objects.toStringHelper(this).add("id", id).add("name", name).add("firstname", firstname)
                .add("email", email).add("password", password).add("events", events).toString();
    }
}

Events.java:

public class Events {

    public Events() {
    }

    private String startEvent;
    private String endEvent;

    public String getStartEvent() {
        return startEvent;
    }

    public void setStartEvent(String startEvent) {
        this.startEvent = startEvent;
    }

    public String getEndEvent() {
        return endEvent;
    }

    public void setEndEvent(String endEvent) {
        this.endEvent = endEvent;
    }

}

Events shouldn't be stored in the database

2 Answers 2

3

From the look of the code, it seems to me that Events shouldn't be stored in the database.

If this is the case, then it should be sufficient to mark them @Transient

@Transient
private List<Events> events;
Sign up to request clarification or add additional context in comments.

3 Comments

Then the '@Transient' annotation says that the property, or method isn't persisted to the database and still can remain there. As '@Id' is on the property it should be fine to leave only on property, but it is possible that you will need to add it to the getter and setter as well.
@JakubBalhar It is not need to add @Transient to a setter.
Thanks for clarification.
2

You need to add mapping for the events property, if you need to store it in the database.

@OneToMany
private List<Events> events;

or

@OneToMany
@JoinColumn
private List<Events> events;

And add the @Entity annotation to the Events class

@Entity
public class Events {

} 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.