-->
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.  [ 2 posts ] 
Author Message
 Post subject: ColumnTransformer using auto Alias String
PostPosted: Fri Nov 01, 2013 5:16 am 
Newbie

Joined: Mon Oct 28, 2013 6:02 am
Posts: 3
hi.

Mysql User Defined Function use encode/decode data.

class....
Code:
@ColumnTransformer(read = "CAST(unseal_text(sMemberId) AS CHAR CHARACTER SET UTF8)", write = "seal_text(CAST(? AS CHAR CHARACTER SET UTF8))")
private String memberId;


db charset euc-kr, but WAS charset UTF-8. I convert UTF-8.

@ColumnTransformer use query
Code:
       CAST(unseal_text(order0_.sMemberId) AS order0_.CHAR order0_.CHARACTER order0_.SET order0_.UTF8) as column8_0_0_,


order0_.CHAR order0_.CHARACTER order0_.SET order0_.UTF8 <== I want not add alias

please help me.


Top
 Profile  
 
 Post subject: Re: ColumnTransformer using auto Alias String
PostPosted: Mon Nov 04, 2013 2:59 am 
Newbie

Joined: Mon Oct 28, 2013 6:02 am
Posts: 3
I found it.

use entities interceptor.
Code:
public class HibernateSecurityInterceptor extends EmptyInterceptor {

   private static final long serialVersionUID = 7049750866908874951L;

   @Override
   public String onPrepareStatement(String sql) {
      // Cast string
      String insertCastStart="CAST(";
      String insertCastEnd=" AS CHAR CHARACTER SET UTF8)";

      Pattern p = Pattern.compile("(?i:unseal_text)");
      Matcher m = p.matcher(sql);

      // find cast point
      List<Integer> castStartPoint = new ArrayList<Integer>();
      while(m.find()){
         castStartPoint.add(m.start());
      }

      // insert increase sql string lenth.
      int offset=0;
      StringBuffer sb = new StringBuffer(sql);
      for(Integer point : castStartPoint){
         sb.insert(point+offset, insertCastStart);
         sb.insert(sb.indexOf(")", point+offset)+1,insertCastEnd);
         offset += insertCastStart.length();
         offset += insertCastEnd.length();
      }

      return super.onPrepareStatement(sb.toString());
   }
}



Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.