Forum » Programiranje » Java Hibernate problem
Java Hibernate problem
boss-tech ::
S hibernate sem naredil 2 tabeli. Tabelo A in B. Tabela A ima poleg svojih atributov tudi tuji ključ do tabele B.
Sedaj bi rad naredil poizvedbo, ki bi mi vrnila vse vrstice iz tabele A (+ B) glede na id.
Naredil sem takole:
Se pravi da bi rad dobil vse vrstice iz A, kjer ima B testNum > 1, vendar dobim napako:
Kako naj naredim da mi bo iskalo po tabeli B?
/** Table B */
@OneToMany(targetEntity=B.class)
@JoinTable(name="B",
joinColumns=
@JoinColumn(name="id"),
inverseJoinColumns=
@JoinColumn(name="B_id")
)
@Column(name = "Bdata", nullable = false)
public List<B> getBData() {
return data;
}
Sedaj bi rad naredil poizvedbo, ki bi mi vrnila vse vrstice iz tabele A (+ B) glede na id.
Naredil sem takole:
DetachedCriteria dc = DetachedCriteria.forClass(B.class);
Criterion c = Restrictions.ge("Bdata.testNum", 1);
dc.add(c);
Criterion idCriterion = Restrictions.in("id", mojId);
dc.add(idCriterion);
List<?> result = getHibernateTemplate().findByCriteria(dc);
Se pravi da bi rad dobil vse vrstice iz A, kjer ima B testNum > 1, vendar dobim napako:
could not resolve property: Bdata.testNum of: dao.hibernate.model.A
Kako naj naredim da mi bo iskalo po tabeli B?
KaRkY ::
Mogoče ti bo to pomagalo:)
By navigating associations using createCriteria() you can specify constraints upon related entities:
The second createCriteria() returns a new instance of Criteria that refers to the elements of the kittens collection.
By navigating associations using createCriteria() you can specify constraints upon related entities:
List cats = sess.createCriteria(Cat.class)
.add( Restrictions.like("name", "F%") )
.createCriteria("kittens")
.add( Restrictions.like("name", "F%") )
.list();The second createCriteria() returns a new instance of Criteria that refers to the elements of the kittens collection.
When you look long into an abyss, the abyss looks into you
Vredno ogleda ...
| Tema | Ogledi | Zadnje sporočilo | |
|---|---|---|---|
| Tema | Ogledi | Zadnje sporočilo | |
| » | SQL vprasanje (strani: 1 2 )Oddelek: Programiranje | 8988 (5667) | BivšiUser2 |
| » | sql join stavki in group byOddelek: Programiranje | 3809 (3444) | GupeM |
| » | [VB] datagridviewOddelek: Programiranje | 2075 (1458) | korenje3 |
| » | [Java] Urejanje baze z JTableOddelek: Programiranje | 1139 (923) | vonNeumann |
| » | MySQL Query VprašanjeOddelek: Izdelava spletišč | 3526 (3291) | overlord_tm |