Hey Guys!
I use OpenJPA in tandem with SpringFramework. I wrote a simple application
which reads some data from MySQL database and faced very weird problem: openjpa
executes an "update" statement when only "select" query is used and no object
modifications are done.
// My service's method looks like this one
@Transactional(readOnly=true)
public void test(String user) {
Query query = m_entityManager.createQuery("select u from User u");
List<User> users = (List<User>) query.getResultList();
for (User u : users) {
if (u.getLoginName().equals(user)) {
System.out.println("Bingo!");
}
}
}
// User class is very simple
@Entity
@Table(name="user")
public class User implements Serializable {
@Id
@Column(name="user_id")
private int m_id;
@Column(name="user_login_name")
private String m_loginName;
// getters and setters are omitted as not essential for problem
understanding
}
// and openjpa's log-output looks like the one below
openjpa.jdbc.SQL - <t 6533862, conn 16102116> executing prepstmnt 16900472
SELECT t0.user_id, t0.user_login_name from t0
openjpa.jdbc.SQL - <t 6533862, conn 16102116> [0 ms] spent
// and this is the problem :(((
openjpa.jdbc.SQL - <t 6533862, conn 16102116> executing prepstmnt 25980092
UPDATE user SET user_login_name = ? WHERE user_id = ? [params=(String) test,
(int) 1]
openjpa.jdbc.SQL - <t 6533862, conn 16102116> [0 ms] spent
It is already three days I spent on fixing the problem with no success :( Would
someone help me please. I am even ready to switch off automatic update
functionality if there were such possibility.
Thanks and best regards,
Sergej