Unable to map ManyToOne relashionship
I have Book User and Basket class.
1 user can have one or more book in basket table.
I want to map that relation but i keep getting the following error:
javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.persister.walking.spi.WalkingException: Association has already been visited: AssociationKey(table=basket,
columns={book_id})
Basket Class
@Entity
public class Basket {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name="book_id")
private Book book;
private long user_id;
public Basket() {}
public Basket(Book book, long user_id) {
this.book = book;
this.user_id = user_id;
}
// Getters and Setters
}
Book Class
@Entity
@Table(name = "book")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class Book implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(name = "title")
private String title;
@Column(name = "isbn")
private String isbn;
@Column(name = "quantity")
private Integer quantity;
@Column(name = "price")
private Double price;
@OneToMany(mappedBy = "book", fetch = FetchType.EAGER)
@Cache(usage = CacheConcurrencyStrategy.NONE)
@JsonIgnoreProperties("book")
private Set<SaleDetails> saleDetails = new HashSet<>();
@ManyToMany(fetch = FetchType.EAGER)
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
@JoinTable(name = "book_author",
joinColumns = @JoinColumn(name = "books_id", referencedColumnName = "id"),
inverseJoinColumns = @JoinColumn(name = "authors_id", referencedColumnName = "id"))
@JsonIgnoreProperties("books")
private Set<Author> authors = new HashSet<>();
@ManyToMany(fetch = FetchType.EAGER)
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
@JoinTable(name = "book_genre",
joinColumns = @JoinColumn(name = "books_id", referencedColumnName = "id"),
inverseJoinColumns = @JoinColumn(name = "genres_id", referencedColumnName = "id"))
private Set<Genre> genres = new HashSet<>();
hibernate jpa
add a comment |
I have Book User and Basket class.
1 user can have one or more book in basket table.
I want to map that relation but i keep getting the following error:
javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.persister.walking.spi.WalkingException: Association has already been visited: AssociationKey(table=basket,
columns={book_id})
Basket Class
@Entity
public class Basket {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name="book_id")
private Book book;
private long user_id;
public Basket() {}
public Basket(Book book, long user_id) {
this.book = book;
this.user_id = user_id;
}
// Getters and Setters
}
Book Class
@Entity
@Table(name = "book")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class Book implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(name = "title")
private String title;
@Column(name = "isbn")
private String isbn;
@Column(name = "quantity")
private Integer quantity;
@Column(name = "price")
private Double price;
@OneToMany(mappedBy = "book", fetch = FetchType.EAGER)
@Cache(usage = CacheConcurrencyStrategy.NONE)
@JsonIgnoreProperties("book")
private Set<SaleDetails> saleDetails = new HashSet<>();
@ManyToMany(fetch = FetchType.EAGER)
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
@JoinTable(name = "book_author",
joinColumns = @JoinColumn(name = "books_id", referencedColumnName = "id"),
inverseJoinColumns = @JoinColumn(name = "authors_id", referencedColumnName = "id"))
@JsonIgnoreProperties("books")
private Set<Author> authors = new HashSet<>();
@ManyToMany(fetch = FetchType.EAGER)
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
@JoinTable(name = "book_genre",
joinColumns = @JoinColumn(name = "books_id", referencedColumnName = "id"),
inverseJoinColumns = @JoinColumn(name = "genres_id", referencedColumnName = "id"))
private Set<Genre> genres = new HashSet<>();
hibernate jpa
Basket domain can not have List<book> it makes no sense. I only need that fot each basket object, instead of id i need the object it self...
– Bruno Miguel
Nov 19 '18 at 15:20
So a Basket can only contain 1 Book, so your description is wrong. Doesn't fix the problem mind, that is utterly Hibernate specific
– Billy Frost
Nov 19 '18 at 16:08
Sorry if i miss explain the problem. I have 3 tables User Book and Basket(id, user_id, book_id) and i'm able to get a list of baskets. But if instead of having private long book_id i try to map to and object i get the error
– Bruno Miguel
Nov 19 '18 at 16:27
If you have someUser
class perhaps actually post it in the question. Otherwise if it is not related to the problem then don't even mention it ... keep the question concise
– Billy Frost
Nov 19 '18 at 17:57
add a comment |
I have Book User and Basket class.
1 user can have one or more book in basket table.
I want to map that relation but i keep getting the following error:
javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.persister.walking.spi.WalkingException: Association has already been visited: AssociationKey(table=basket,
columns={book_id})
Basket Class
@Entity
public class Basket {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name="book_id")
private Book book;
private long user_id;
public Basket() {}
public Basket(Book book, long user_id) {
this.book = book;
this.user_id = user_id;
}
// Getters and Setters
}
Book Class
@Entity
@Table(name = "book")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class Book implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(name = "title")
private String title;
@Column(name = "isbn")
private String isbn;
@Column(name = "quantity")
private Integer quantity;
@Column(name = "price")
private Double price;
@OneToMany(mappedBy = "book", fetch = FetchType.EAGER)
@Cache(usage = CacheConcurrencyStrategy.NONE)
@JsonIgnoreProperties("book")
private Set<SaleDetails> saleDetails = new HashSet<>();
@ManyToMany(fetch = FetchType.EAGER)
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
@JoinTable(name = "book_author",
joinColumns = @JoinColumn(name = "books_id", referencedColumnName = "id"),
inverseJoinColumns = @JoinColumn(name = "authors_id", referencedColumnName = "id"))
@JsonIgnoreProperties("books")
private Set<Author> authors = new HashSet<>();
@ManyToMany(fetch = FetchType.EAGER)
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
@JoinTable(name = "book_genre",
joinColumns = @JoinColumn(name = "books_id", referencedColumnName = "id"),
inverseJoinColumns = @JoinColumn(name = "genres_id", referencedColumnName = "id"))
private Set<Genre> genres = new HashSet<>();
hibernate jpa
I have Book User and Basket class.
1 user can have one or more book in basket table.
I want to map that relation but i keep getting the following error:
javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.persister.walking.spi.WalkingException: Association has already been visited: AssociationKey(table=basket,
columns={book_id})
Basket Class
@Entity
public class Basket {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name="book_id")
private Book book;
private long user_id;
public Basket() {}
public Basket(Book book, long user_id) {
this.book = book;
this.user_id = user_id;
}
// Getters and Setters
}
Book Class
@Entity
@Table(name = "book")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class Book implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(name = "title")
private String title;
@Column(name = "isbn")
private String isbn;
@Column(name = "quantity")
private Integer quantity;
@Column(name = "price")
private Double price;
@OneToMany(mappedBy = "book", fetch = FetchType.EAGER)
@Cache(usage = CacheConcurrencyStrategy.NONE)
@JsonIgnoreProperties("book")
private Set<SaleDetails> saleDetails = new HashSet<>();
@ManyToMany(fetch = FetchType.EAGER)
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
@JoinTable(name = "book_author",
joinColumns = @JoinColumn(name = "books_id", referencedColumnName = "id"),
inverseJoinColumns = @JoinColumn(name = "authors_id", referencedColumnName = "id"))
@JsonIgnoreProperties("books")
private Set<Author> authors = new HashSet<>();
@ManyToMany(fetch = FetchType.EAGER)
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
@JoinTable(name = "book_genre",
joinColumns = @JoinColumn(name = "books_id", referencedColumnName = "id"),
inverseJoinColumns = @JoinColumn(name = "genres_id", referencedColumnName = "id"))
private Set<Genre> genres = new HashSet<>();
hibernate jpa
hibernate jpa
asked Nov 19 '18 at 14:51
Bruno MiguelBruno Miguel
216
216
Basket domain can not have List<book> it makes no sense. I only need that fot each basket object, instead of id i need the object it self...
– Bruno Miguel
Nov 19 '18 at 15:20
So a Basket can only contain 1 Book, so your description is wrong. Doesn't fix the problem mind, that is utterly Hibernate specific
– Billy Frost
Nov 19 '18 at 16:08
Sorry if i miss explain the problem. I have 3 tables User Book and Basket(id, user_id, book_id) and i'm able to get a list of baskets. But if instead of having private long book_id i try to map to and object i get the error
– Bruno Miguel
Nov 19 '18 at 16:27
If you have someUser
class perhaps actually post it in the question. Otherwise if it is not related to the problem then don't even mention it ... keep the question concise
– Billy Frost
Nov 19 '18 at 17:57
add a comment |
Basket domain can not have List<book> it makes no sense. I only need that fot each basket object, instead of id i need the object it self...
– Bruno Miguel
Nov 19 '18 at 15:20
So a Basket can only contain 1 Book, so your description is wrong. Doesn't fix the problem mind, that is utterly Hibernate specific
– Billy Frost
Nov 19 '18 at 16:08
Sorry if i miss explain the problem. I have 3 tables User Book and Basket(id, user_id, book_id) and i'm able to get a list of baskets. But if instead of having private long book_id i try to map to and object i get the error
– Bruno Miguel
Nov 19 '18 at 16:27
If you have someUser
class perhaps actually post it in the question. Otherwise if it is not related to the problem then don't even mention it ... keep the question concise
– Billy Frost
Nov 19 '18 at 17:57
Basket domain can not have List<book> it makes no sense. I only need that fot each basket object, instead of id i need the object it self...
– Bruno Miguel
Nov 19 '18 at 15:20
Basket domain can not have List<book> it makes no sense. I only need that fot each basket object, instead of id i need the object it self...
– Bruno Miguel
Nov 19 '18 at 15:20
So a Basket can only contain 1 Book, so your description is wrong. Doesn't fix the problem mind, that is utterly Hibernate specific
– Billy Frost
Nov 19 '18 at 16:08
So a Basket can only contain 1 Book, so your description is wrong. Doesn't fix the problem mind, that is utterly Hibernate specific
– Billy Frost
Nov 19 '18 at 16:08
Sorry if i miss explain the problem. I have 3 tables User Book and Basket(id, user_id, book_id) and i'm able to get a list of baskets. But if instead of having private long book_id i try to map to and object i get the error
– Bruno Miguel
Nov 19 '18 at 16:27
Sorry if i miss explain the problem. I have 3 tables User Book and Basket(id, user_id, book_id) and i'm able to get a list of baskets. But if instead of having private long book_id i try to map to and object i get the error
– Bruno Miguel
Nov 19 '18 at 16:27
If you have some
User
class perhaps actually post it in the question. Otherwise if it is not related to the problem then don't even mention it ... keep the question concise– Billy Frost
Nov 19 '18 at 17:57
If you have some
User
class perhaps actually post it in the question. Otherwise if it is not related to the problem then don't even mention it ... keep the question concise– Billy Frost
Nov 19 '18 at 17:57
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53377152%2funable-to-map-manytoone-relashionship%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53377152%2funable-to-map-manytoone-relashionship%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Basket domain can not have List<book> it makes no sense. I only need that fot each basket object, instead of id i need the object it self...
– Bruno Miguel
Nov 19 '18 at 15:20
So a Basket can only contain 1 Book, so your description is wrong. Doesn't fix the problem mind, that is utterly Hibernate specific
– Billy Frost
Nov 19 '18 at 16:08
Sorry if i miss explain the problem. I have 3 tables User Book and Basket(id, user_id, book_id) and i'm able to get a list of baskets. But if instead of having private long book_id i try to map to and object i get the error
– Bruno Miguel
Nov 19 '18 at 16:27
If you have some
User
class perhaps actually post it in the question. Otherwise if it is not related to the problem then don't even mention it ... keep the question concise– Billy Frost
Nov 19 '18 at 17:57