java - Hibernate query not finding "pending" entites in same transaction -
i've got app importing data manytomany structure.
@table(name="content") class content { @column(.., unqiue=true) string str; } @table(name="group") class group { @jointable("group_content"..) list<content> contentlist; }
the content
has unique column str
(as seen above) used app identify content exist in database - , if re-use entity rather adding again.
this done findbystr(string str)
method in contentdao
implementation. it's implemented namedquery
(from content c c.str = :str
).
when run import both groups , content new , groups refeer same (new) content seem findbystr
query returns null
.
the query works fine outside of scenario seems when content objects has been created, not committed, query not detect them.
currently work around i'm keeping map<string, content>
double check against if query returns null
.
hibernate not execute insert statements immidiately. make sure before each call findbystr
sql inserts new objects sent db. can ensure doing:
- tell hibernate take account new objects. example can executing
session.save(group)
each new group object (which take account related content objects) - execute 1 time
session.flush()
normally after these changes must available query in same transaction.
Comments
Post a Comment