java - Join columns with ForeignKeys -


i created entity-bean maps order-table of mssql server 2012. far works fine, i'd join columns article-view provide more information selected articles.

the order consists of several rows id prime-key , article-nr foreign-key.

i tried map view articles article-entity due amount of rows (>10.000) slows down (but works should... incredibly slow... there's no other need map view more - except 3 rows of information). i'd join necessary columns order-entity.

but don't working...

i tried annotation "namedquery"

@entity @namednativequery(name = "joinnecessary",  query = "select order.pk_id, order.fk_orderid, order.fk_articlenr, order.amount, article.description, article.price  order left outer join article  on order.fk_articlenr=article.pk_articlenr", resultclass = order.class) 

i'm not sure problem is... records-entity has list of order-entities , displays them.

for(orders o: orderlist){ 

in line following errors:

severe: invalid object name 'order'. exception in thread "main" org.hibernate.exception.sqlgrammarexception: not initialize collection: [qohelet.record.orders#1] @ org.hibernate.exception.sqlstateconverter.convert(sqlstateconverter.java:67)

in literature found interesting mapping 1:1-relations. (from perspective relation can seen such one) if found @secondarytable-annotation could fine solution problems:

@table(name = "order") @secondarytable(name = "article", pkjoincolumns = {     @primarykeyjoincolumn(name = "pk_articlenr", referencedcolumnname = "fk_articlenr") }) 

the other columns join this:

@column(table = "article") private string description; 

but guess annotation "primarykeyjoincolumn" isn't named no reason...

initial sessionfactory creation failed.org.hibernate.annotationexception: secondarytable joincolumn cannot reference non primary key

java.lang.exceptionininitializererrorexception in thread "main"

is there annotation has effect i'd get? or using current ones wrong? thanks!

the word order special statement in t-sql. -> use [ ] :

select [order].*  [order] left outer join article on [order].fk_articlenr = article.pk_articlenr order price 

Comments