-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: retrieving record issue
PostPosted: Tue Jun 29, 2010 12:04 am 
Newbie

Joined: Mon Jun 28, 2010 10:36 pm
Posts: 2
Hi,

I have a problem with retrieving record from the database.

Environment: Java 1.5, spring 3.x, hibernate 3.5.2

User.java:
Code:
@Entity
@Table(name = "user")
public final class User implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "id", nullable = false, length = 11)
    private int id;

    @Column(name = "username", nullable = false, length = 21)
    private String username;

    @Column(name = "password", nullable = false, length = 32)
    private String password;

    @Column(name = "token", nullable = false, length = 32)
    private String token;

    @Column(name = "enabled", nullable = false, length = 1)
    private boolean enabled;

    @ManyToMany(cascade = CascadeType.ALL)
    @JoinTable(name = "user_role", joinColumns = { @JoinColumn(name = "user_id") }, inverseJoinColumns = { @JoinColumn(name = "role_id") })
    private Set<UserRole> userRoles;

    @OneToOne(cascade = CascadeType.ALL)
    @JoinTable(name = "profile", joinColumns = { @JoinColumn(name = "user_id") }, inverseJoinColumns = { @JoinColumn(name = "id") })
    private Profile profile;

  ...get ... set for all properties


Profile.java:
Code:
@Entity
@Table(name = "profile")
public final class Profile implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @OneToOne
    @JoinColumn(name = "user_id")
    private User user;

    @Column(name = "email", nullable = false, length = 64)
    private String email;

    @Column(name = "first_name", nullable = false, length = 30)
    private String firstName;

    @Column(name = "last_name", nullable = false, length = 30)
    private String lastName;

    @Column(name = "gender", nullable = false, length = 1)
    private boolean gender;

    @Column(name = "reg_ip", nullable = true, length = 254)
    private String regIp;

    ... get ... set


code from dao:
Code:
public User getUser(final String username, final String securityToken)
       throws DataAccessException {
   HibernateCallback callback = new HibernateCallback() {

       public Object doInHibernate(Session session) throws HibernateException, SQLException {
      Criteria criteria = session.createCriteria(User.class);
      criteria.add(Restrictions.eq("username", username));
      criteria.add(Restrictions.eq("token", securityToken));
      return (User) criteria.uniqueResult();
       }
   };
   return (User) getHibernateTemplate().execute(callback);
    }


SQL :
Code:
CREATE TABLE  `dta`.`profile` (
  `user_id` int(11) NOT NULL DEFAULT '0',
  `email` varchar(64) NOT NULL,
  `first_name` varchar(30) NOT NULL,
  `last_name` varchar(30) NOT NULL,
  `gender` bit(1) NOT NULL,
  `reg_ip` varchar(254) DEFAULT NULL,
  KEY `user_id` (`user_id`),
  CONSTRAINT `fk_pr_u` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE  `dta`.`user` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `username` varchar(21) NOT NULL,
  `password` varchar(32) NOT NULL,
  `token` varchar(32) NOT NULL,
  `enabled` bit(1) NOT NULL DEFAULT b'1',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;


xml definition:
Code:
<bean id="dataSource"
      class="org.apache.commons.dbcp.BasicDataSource"
      destroy-method="close">
      <property name="driverClassName" value="com.mysql.jdbc.Driver" />
      <property name="url"
         value="jdbc:mysql://localhost:3306/mydb?useUnicode=true" />
      <property name="username" value="login" />
      <property name="password" value="pass" />
   </bean>


   <bean id="sessionFactory"
      class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
      <property name="dataSource" ref="dataSource" />
      <property name="annotatedClasses">
         <list>
            <value>com.dta.model.entity.User</value>
            <value>com.dta.model.entity.Invite</value>
            <value>com.dta.model.entity.Profile</value>
            <value>com.dta.model.entity.UserRole</value>
         </list>
      </property>
      <property name="hibernateProperties">
         <value>
            hibernate.dialect=org.hibernate.dialect.MySQLInnoDBDialect
            hibernate.show_sql=true
            hibernate.format_sql=true
            hibernate.cglib.use_reflection_optimizer = false
            hibernate.use_sql_comments=true
            hibernate.connection.charSet=UTF-8
         </value>
      </property>
   </bean>

   <tx:annotation-driven transaction-manager="txManager" />

   <bean id="txManager"
      class="org.springframework.orm.hibernate3.HibernateTransactionManager">
      <property name="sessionFactory" ref="sessionFactory" />
   </bean>

   <bean id="userDao" class="com.dta.model.dao.UserDao">
      <property name="sessionFactory" ref="sessionFactory" />
   </bean>



When I trying to retrieve existing record from the user, I got next message:
Quote:
DEBUG SQL -
/* criteria query */ select
this_.id as id9_1_,
this_.enabled as enabled9_1_,
this_.password as password9_1_,
this_.token as token9_1_,
this_.username as username9_1_,
profile2_.user_id as user6_10_0_,
profile2_.email as email10_0_,
profile2_.first_name as first2_10_0_,
profile2_.gender as gender10_0_,
profile2_.last_name as last4_10_0_,
profile2_.reg_ip as reg5_10_0_
from
user this_
left outer join
profile this_1_
on this_.id=this_1_.user_id
left outer join
profile profile2_
on this_.id=profile2_.user_id
where
this_.username=?

DEBUG SQL -
/* load com.dta.model.entity.User */ select
user0_.id as id9_1_,
user0_.enabled as enabled9_1_,
user0_.password as password9_1_,
user0_.token as token9_1_,
user0_.username as username9_1_,
profile1_.user_id as user6_10_0_,
profile1_.email as email10_0_,
profile1_.first_name as first2_10_0_,
profile1_.gender as gender10_0_,
profile1_.last_name as last4_10_0_,
profile1_.reg_ip as reg5_10_0_
from
user user0_
left outer join
profile user0_1_
on user0_.id=user0_1_.user_id
left outer join
profile profile1_
on user0_.id=profile1_.user_id
where
user0_.id=?

....last request repeated n times and than I got the following:

Invalid access of stack red zone 0x117c92ea0 rip=0x117352858


Please advise what I do wrong. Thanks for answers.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.