org.hibernate.MappingException: Could not get constructor for org.hibernate.persister.entity.SingleTableEntityPersister

0

Self Advertisement
—–Start of Advertisement——-
BUILD CAR POOL SOLUTIONS ON ANY DEVICE TO RUN ANYWHERE (www.mcruiseon.com). Introducing mCruiseOn, the java library /json api’s that you can use to build a car pool solution. Be the next avego.com, carpooling.com, zimride.com. mCruiseOn is your one stop API on EC2.
——End of Advertisement——-

I just enabled log4j, and stopped printing stacktrace on exceptions. So the errors I started to get were very cryptic. Printing stacktrace is important even after you have log4j consuming the exception object.
Once I uncommented e.printStackTrace(), I got more meaningful exception stacktraces which helped identify the root cause.
In my case
– Did not have the setMethod for a new primary key defined, in the class refered by the hbm file.
– Had java.util.Integer instead of java.lang.Integer
– for a variable acPreference I had getACPreference, instead I should have had getAcPreference

Designing a Data Model, process and tools to use…

0

Normalization is generally learnt during our college days from database concepts, but we tend to forget the very basic need for normalization as we acquire new knowledge over the years. We ignore normalization to avoid taking time to design our database. I mean, why have a bunch of tables, why not just 1 table with everything in it.

So why normalize our database ?

The answer is simple, databases need to be designed in a way so that the following issues are “prevented” at the root level itself by the design itself.

  1. if a record is deleted, other tables containing the record details should deleted in a cascaded format.
  2. Every table must have exactly 1 “intent”. Customer_Id, Payment_1, Payment_2, Payment_3 is NOT the way to design your database. Simply because retrieving data will be really slow. Now you are considering a few transactions, but in future you will not be given a dedicated server for just this one app for just this small set of users. In the real world, databases, filesystems, storage, network, cpu, memory is all shared. If your one app takes most of the cpu/memory resources, very soon it will be “out” of production.
  3. Performance, every database indexes tables to ensure fast retrieval. What does indexing mean, you ask ? Well, the database reads your table, and creates multiple pointers to your record, so that its not a sequential search. Creates a BTree, to prevent linear search.
  4. Foreign key fundamentals help keep your data “integrity” intact. (extension of point 1). Integrity here means, that your database has GOOD data, not stale not useless. Imagine a database that retains salary information of all employee’s even after they have resigned from the organization. Crazy, yes, its possible if you dont form the correct foreign key relationships.
  5. Oh forget all this, I’ll just take care of it in code. Well, if you take 2 mins to think about it, you will not need to write, test, maintain, bug fix 100-500 lines of code, if you just design your db/tables right.

I am not trying to convince you on the benefits of normalization, I am just reminding you. You are already convinced, but deep in your mind you believe that its needed, just lazy to put in that time. And I understand, database design needs time, thinking time. A step by step process, since it does take your whole brain to design it right.

The right tools play a very important role for designing your database. Remember it takes both the sides of your brain to design a database. So slow down.

I use ubuntu for my development work. For db design we need GUI tools. After some research I have zeroed on mysqlworkbench. It is a nice tool for reverse engineering your table and reviewing the schema graphically. Its quicker, less painful and a reverse engineered from existing tables. Not many tools produce this result.

To change relationships between tables mysqlworkbench sucks big time. Its a pain to use. So for this I use phpmyadmin. Its clumsy at best, but does the job.

So use phpmyadmin to edit relationships and review the change, I reverse engineer with mysqlworkbench.

phpmysqladmin, if you need to create a foreign key in table A, which is a column in table B. You need to create a index for the column in table B. Then Goto table A, “relation view”, and use the drop down to select your column from table B. Also set your “on delete”, “on update” rules.

I hope this is helpful. If not, please comment.

Interesting Links
For understanding workbench er diagram (http://www.smartdraw.com/resources/tutorials/cardinality-notations/)

MySQL Admin Tools (workbench vs open source browser based)

0

To start with, let me tell you that MySQL workbench sucks big time. I exported my tables to the workbench, and created my ER diagram. As I try to apply changes, all hell breaks loose. Obviously workbench has not sequenced its mysql statements in order correctly, so there are cyclic changes being made. Very immature of a product I must say. Does not incorporate graph theory fundamentals to solve sequencing of its mysql statements to apply the ER diagram to the DB schema. I mean, why create a bunch of mysql statements if you can run it. Over and above that we all know how pathetic mysql error messages are. Just crazy.

Solution
So I am only going to use WorkBench for viewing my schema, which makes it easy for me to think of my data model. Graphically seeing is a bonus. But use phpmysqladmin to do any changes to my schema.

Was trying to do things on workbench for last 3-4 hours, and finally 5 mins of phpmysqlamdin did the trick.

Include Log4j to my java project in eclipse

0

Well, like any programmer, I started with System.out.println’s for my logging and debugging needs. But only after I wrote myself a set of test cases. As you assumed right I ran out of thought process to organize my log’s very soon. As I was debugging stuff, I realized that my logs not only need to be categorized they need to be “intended”. When I “intended” I meant that sometime in future I want to be able to say something like “show me logs of all threading happening on my server”. So I know who is using my threads, when and is some client eating up my threadpool ? I also want to be able to drive down to the client level to figure out who exactly is eating it up.

The that is “important” for me, not urgent as yet. As any good time management advice will tell you, to focus on your urgent and important. So currently I need to be able to just organize my logs into the regular 4 levels, fatal, error, info and debug. So here goes. I choose Log4j for many reasons
– Tried and tested
– A lot of help on the net for log4j
– Best Practices are already identified, documented and followed (http://juliusdavies.ca/logging.html)
/**
* Logger Design
* Should be greppable
* Separate files for separate areas of interest
* Device/Connection/StreamManager threads
* Stream Management
* Request Issues
* Database Issues
* Memcached Issues
* TimeStamps with timezones from server and client and down to nanoseconds (yyyy-MM-dd/HH:mm:ss.SSS/zzz) Java does not support nanoseconds
* Identity (who tried to do what)
* Single Line (no multiple line’s. Except, exceptions
* When did user last login ?
* Error reported to user “must” be logged (exact Error)
* Every Class to have
* public static final Logger log = Logger.getLogger(MyClass.class) ;
*/

I did encounter some trouble starting up. So this blog will help those who want to startup too. The the above advice, I also did the following
– In my main method I did
PropertyConfigurator.configure(“log4j.properties”);
– Added log.properties under the same level as src directory on my eclipse project
Project
src
….
log4j.properties
– My log4j.properties contents are
log4j.rootLogger=DEBUG, CA
log4j.appender.CA=org.apache.log4j.ConsoleAppender
log4j.appender.CA.layout=org.apache.log4j.PatternLayout
log4j.appender.CA.layout.ConversionPattern=%-4r [%t] %-5p %c %x – %m%n

#log4j.appender.A1.all=\u001B[1;37m
#log4j.appender.A1.fatal=\u001B[1;31m
#log4j.appender.A1.error=\u001B[0;31m
#log4j.appender.A1.warn=\u001B[1;33m
#log4j.appender.A1.info=\u001B[0;37m
#log4j.appender.A1.debug=\u001B[0;36m
#log4j.appender.A1.stacktrace=\u001B[0;31m
#log4j.appender.A1.defaultcolor=\u001B[1;37m

#AnsiColorLogger.ERROR_COLOR=2;31
#AnsiColorLogger.WARNING_COLOR=2;35
#AnsiColorLogger.INFO_COLOR=2;36
#AnsiColorLogger.VERBOSE_COLOR=2;32
#AnsiColorLogger.DEBUG_COLOR=2;34
#
#AnsiColorLogger.*=Attribute;Foreground;Background
#
#Attribute is one of the following:
#0 -> Reset All Attributes (return to normal mode)
#1 -> Bright (Usually turns on BOLD)
#2 -> Dim
#3 -> Underline
#5 -> link
#7 -> Reverse
#8 -> Hidden
#
#Foreground is one of the following:
#30 -> Black
#31 -> Red
#32 -> Green
#33 -> Yellow
#34 -> Blue
#35 -> Magenta
#36 -> Cyan
#37 -> White
#
#Background is one of the following:
#40 -> Black
#41 -> Red
#42 -> Green
#43 -> Yellow
#44 -> Blue
#45 -> Magenta
#46 -> Cyan
#47 -> White
#org.apache.tools.ant.listener.AnsiColorLogger=.ERROR_COLOR=2;31
#org.apache.tools.ant.listener.AnsiColorLogger=.WARNING_COLOR=2;35
#org.apache.tools.ant.listener.AnsiColorLogger=.INFO_COLOR=2;36
#org.apache.tools.ant.listener.AnsiColorLogger=.VERBOSE_COLOR=2;32
#org.apache.tools.ant.listener.AnsiColorLogger=.DEBUG_COLOR=2;34

I am still trying to get colors in my log, but that does not work. When I get it up and running, I’ll edit this post with more. If you have a solution on this, please comment.