Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Object Relational Mapping
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Devaka Cooray
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Jeanne Boyarsky
Tim Cooke
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Tim Moores
Mikalai Zaikin
Carey Brown
Bartenders:
Forum:
Object Relational Mapping
Outer join between 3 entities in HQL
Hajdu Attila
Greenhorn
Posts: 6
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi,
I have 2 normal tables, and a view table.
Curse.java:
@Entity @Table(name = "CURSES") public class Curse implements Serializable { @EmbeddedId @AttributeOverrides( { @AttributeOverride(name = "curseId", column = @Column(name = "CURSE_ID", nullable = false, length = 16)), @AttributeOverride(name = "semesterId", column = @Column(name = "SEMESTER_ID", nullable = false, length = 10)) }) private CurseId id; @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "SEMESTER_ID", nullable = false, insertable = false, updatable = false) private Semester semester; @ManyToOne(fetch = FetchType.LAZY) @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "curse") private List<UserCurse> users = new ArrayList<UserCurse>(); }
UserCurse.java:
@Entity @Table(name = "USERS_CURSES") public class UserCurse implements java.io.Serializable { @EmbeddedId @AttributeOverrides( { @AttributeOverride(name = "userId", column = @Column(name = "USER_ID", nullable = false, length = 16)), @AttributeOverride(name = "curseId", column = @Column(name = "CURSE_ID", nullable = false, length = 16)), @AttributeOverride(name = "semesterId", column = @Column(name = "SEMESTER_ID", nullable = false, length = 10)) }) private UserCurseId id; @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "USER_ID", nullable = false, insertable = false, updatable = false) private User user; @ManyToOne(fetch = FetchType.LAZY) @JoinColumns(value = { @JoinColumn(name = "CURSE_ID", referencedColumnName = "CURSE_ID", nullable = false, insertable = false, updatable = false), @JoinColumn(name = "SEMESTER_ID", referencedColumnName = "SEMESTER_ID", nullable = false, insertable = false, updatable = false) }) private Curse curse; }
And a view table
SELECT CURSE_ID, SEMESTER_ID, COUNT(USER_ID) AS USER_COUNT FROM USERS_CURSES GROUP BY CURSE_ID, SEMESTER_ID
View table reprezenter class:
@Entity @Table(name = "CURSES_VIEW") public class CursesView implements Serializable { @Id @Column(name = "CURSE_ID", insertable = false, updatable = false, nullable = false, length = 16) private String curseId; @Column(name = "SEMESTER_ID", insertable = false, updatable = false,nullable = false, length = 10) private String semesterId; @Column(name = "USER_COUNT", insertable = false, updatable = false, nullable = false, precision = 22, scale = 0) private BigDecimal userCount; }
I want to
select cur, usCurs.id.userId, curView.userCount from Curse cur left outer join cur.users usCurs with usCurs.id.userId = :userId left outer join CursesView curView
I catch: database.DataAccessLayerException: org.hibernate.hql.ast.QuerySyntaxException: Path expected for join!
Thank you!
Arch enemy? I mean, I don't like you, but I don't think you qualify as "arch enemy". Here, try this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Problem with onetomany relantionship with JPA 2.0
Question about mapping and persisting in Hibernate/JBoss Seam
Populate child table foreign keys from primary table?
same primary key as foreign key in two table[Hibernate Mapping]
Edit primary key, if it's a foreign key
More...