-->
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.  [ 3 posts ] 
Author Message
 Post subject: Is it possible to use postgresql's chkpass type ?
PostPosted: Mon Nov 29, 2010 6:24 am 
Newbie

Joined: Fri Oct 21, 2005 4:58 am
Posts: 1
If yes, how, I have an "operator does not exist: chkpass = bytea Hint: No operator matches the given name and argument type(s)" error.

Thanks


Top
 Profile  
 
 Post subject: Re: Is it possible to use postgresql's chkpass type ?
PostPosted: Fri Apr 27, 2012 6:42 pm 
Newbie

Joined: Fri Apr 27, 2012 6:23 pm
Posts: 3
You should use the @TypeDefs, @Type and @Column(columnDefinition=chkpass) annotations in your class. Also, you will have to specify how to handle the chkpass for hibernate with a class that extends org.hibernate.usertype.UserType. You can see an example in my blog. Here is the DTO Example:
Code:
@TypeDefs({ @TypeDef(name="chkpass", typeClass=com.dtorres.customTypes.Chkpass.class) })
@Entity
@Table(name="idm_user", uniqueConstraints = @UniqueConstraint(columnNames = { "user_name" }))
public class User {
   @Id
   @Column(name="user_id", insertable=false, updatable=false)
   @SequenceGenerator(name = "user_id_seq", sequenceName = "idm_user_user_id_seq")
   @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "user_id_seq")
   private long userId;
   
   @Column(name="user_name")
   private String userName;
   
   @Column(name="password", columnDefinition="chkpass", updatable=false, nullable=false)
   @Type(type = "chkpass")
   private String password;...

And part of the custom type:
Code:
public class Chkpass implements UserType {

   @Override
   public Object nullSafeGet(ResultSet inResultSet, String[] names, Object o)
         throws HibernateException, SQLException {
      Object tmp = inResultSet.getObject(names[0]);
      return inResultSet.wasNull() ? null : tmp.toString();
   }

   @Override
   public void nullSafeSet(PreparedStatement inPreparedStatement, Object o,
         int i) throws HibernateException, SQLException {
      if (o == null)
         inPreparedStatement.setNull(i, Types.VARCHAR);
      else
         inPreparedStatement.setObject(i, o, Types.OTHER);
   }...
.

This worked for me just fine, but the chkpass has some limitations, like when starting a password with colon ( : ).

_________________
Diego Alejandro Torres Fuerte
-----------------------------------
Developer
E. diego.torres.fuerte@gmail.com


Top
 Profile  
 
 Post subject: Re: Is it possible to use postgresql's chkpass type ?
PostPosted: Sat May 05, 2012 11:52 am 
Newbie

Joined: Fri Apr 27, 2012 6:23 pm
Posts: 3
Check the source code of the provided solution @ Diego's gitHub.

_________________
Diego Alejandro Torres Fuerte
-----------------------------------
Developer
E. diego.torres.fuerte@gmail.com


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

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.