Question
Java hibernate questions: book.java import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Set; import javax.persistence.CascadeType; import javax.persistence.CollectionTable; import javax.persistence.Column; import javax.persistence.ElementCollection; import javax.persistence.Embeddable; import javax.persistence.Id; import
Java hibernate questions:
book.java
import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Set; import javax.persistence.CascadeType; import javax.persistence.CollectionTable; import javax.persistence.Column; import javax.persistence.ElementCollection; import javax.persistence.Embeddable; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.OneToMany; import javax.persistence.OneToOne; import javax.persistence.Table; import javax.persistence.Entity; import javax.persistence.FetchType; @Entity @Table(name = "book") // POJO class public class book { @Id @Column(name = "bookId") public int id; @Column(name = "bookName") public String bookName; public int getId() { return id; } public void setId(int id) { this.id = id; } public String getBookName() { return bookName; } public void setBookName(String bookName) { this.bookName = bookName; } @ElementCollection(fetch = FetchType.LAZY) @CollectionTable(name = "book_tag", joinColumns = @JoinColumn(name = "b__id",referencedColumnName="bookId")) @Column(name = "b_tag") private Set
App.java
import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; import java.util.List; import java.util.Set; import javax.persistence.Query; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.cfg.Configuration; // Main class public class App { Configuration c = new Configuration(); SessionFactory sessionFactory1 = c.buildSessionFactory(); public static void mainTemp(String[] args) { Configuration configuration = new Configuration(); configuration.configure("hibernate.cfg.xml"); configuration.addAnnotatedClass(book.class); configuration.addAnnotatedClass(Tag.class); configuration.addAnnotatedClass(LitItem.class); // Create Session Factory SessionFactory sessionFactory = configuration.buildSessionFactory(); // Initialize Session Object } // Main driver method public static void main(String[] args) { // Create Configuration Configuration configuration = new Configuration(); configuration.configure("hibernate.cfg.xml"); configuration.addAnnotatedClass(book.class); // Create Session Factory SessionFactory sessionFactory = configuration.buildSessionFactory(); // Initialize Session Object Session session = sessionFactory.openSession(); session.beginTransaction(); book maths = new book(); maths.setId(3); maths.setBookName("CSC"); Set
query.setParameter(" cs1", tags) ; List
}}
In the program there is an exception that there is problem of dereferencing data, , how to remove the error and execute the select query to obtain distinct output for a bookName with multiple tags. without using the keyword distinct? give output too
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started