RSSArchive for November, 2014

Symfony | Doctrine | Error | SQLSTATE[HY000]: General error: 1005 Can’t create table XXX.#sql-818 _1′ (errno: 121). Failing Query:” ALTER TABLE xxx ADD CONSTRAINT …. FOREIGN KEY (xyz) REFERENCES XXX(id) ON DELETE CASCADE”

Symfony is a web application framework written in PHP which follows the model-view-controller (MVC) paradigm . A symfony developer may use Object-Relational Mapping (ORM) – Propel or Doctrine . The earlier version of symfony supported propel and i was using it . But in updated versions symfony supported Doctrine and was forced to update my skills in ORM .

Configuring symfony is pretty simple and model and sql was generated successfully . But on executing the command line argument to insert sql .

[php]

symfony doctrine:insert-sql

[/php]

i got an error :

SQLSTATE[HY000]: General error: 1005 Can’t create table XXX.#sql-818_1′ (errno: 121). Failing Query:” ALTER TABLE xxx ADD CONSTRAINT …. FOREIGN KEY (XYZ) REFERENCES XXX(id) ON DELETE CASCADE”

The error got on my nerves and couldn’t figure out what was it all about . But i was sure its something related to foreign key and after some research i got a fix for it and i am sharing it with you .

There is an issue with your ID columns. Normally this has to do with the foreign key and primary keys having different length constraints. Your fix:

Make sure that the length constraints match. If you aren’t specifying a length, you can simply remove the ID field from your schema.yml, and let Doctrine create it for you, or if you want to be explicit, you can set a length and make sure it is matched in the related foreign key field.

MetroUsers:
actAs: { Timestampable: ~ }
columns:
username: { type: string(255), notnull: true, unique: true }
password: { type: string(255), notnull: true }
hash: { type: string(255), notnull: true }

MetroUserDetails:
actAs: { Timestampable: ~ }
columns:
metro_user_id: { type: integer, notnull: true }
ref_from: { type: string(255), notnull: true, unique: true }
mobilenumber: { type: string(255), notnull: true }
is_mobile_valid: { type: boolean, notnull: true, default: 0 }
email_id: { type: string(255), notnull: true }
relations:
MetroUsers: { onDelete: CASCADE, local: metro_user_id, foreign: id, foreignAlias: MetroUserDetail }

Here id is generated automatically for MetroUsers and make sure that metro_user_id is of type integer .

Hibernate Project Errors – Java – MYSQL 5.0

In this article I am sharing my experience on running my first Hibernate Project.

java-hibernate

I started with my first Hibernate project and followed the steps as instructed within the Tutorial. But on running it I was getting the below error.

[html]

log4j:WARN No appenders could be found for logger (org.hibernate.cfg.annotations.Version).
log4j:WARN Please initialize the log4j system properly.
Exception in thread “main” org.hibernate.HibernateException: /hibernate.cfg.xml not found
at org.hibernate.util.ConfigHelper.getResourceAsStream(ConfigHelper.java:170)
at org.hibernate.cfg.Configuration.getConfigurationInputStream(Configuration.java:1453)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1475)
at org.hibernate.cfg.AnnotationConfiguration.configure(AnnotationConfiguration.java:1017)
at org.hibernate.cfg.AnnotationConfiguration.configure(AnnotationConfiguration.java:64)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1462)
at org.hibernate.cfg.AnnotationConfiguration.configure(AnnotationConfiguration.java:1011)
at com.hibernate.chapter.HelloEmployee.main(HelloEmployee.java:18)

[/html]

Resolution:

I had to spent some time to figure out what I missed and finally the issue was resolved.

The mistake I did was I pasted hibernate.cfg.xml and log4j.properties files thru Eclipse IDE and file got placed within the project root path as you see below.

img

The classpath would be SET to src and the project will search for these files within the scr folder on compile time; so you would need to move the two files manually into the src folder which will resolve the issue.

Hope this helped !

How to set up Maven Build Tool in Windows ?

Hello I’m back with a new article on setting up Maven Tool within your MS Windows machine.

Maven is a build automation tool used primarily for Java projects which describes how software is built and it describes its dependencies.

1. Check if Maven is already installed on your system.

It would be better if we confirm that Maven is not installed on your system. :)

Goto MS DOS and put mvn –version command.

If you see the below screen with error message : ‘mvn’ is not recognized as an internal or external command, operable program or batch file.

0

2. Download and Unzip Maven

Maven is an Apache Product so you would need to download it from – http://maven.apache.org/

1

On clicking the above Download Link you would be redirected to the download page.

2

Make sure you download the Binary Zip for MS Windows and extract it to a folder as you need. I created a below folder structure; if interested you can also follow it.

3

ie; the path is : D:\Program Files\Apache Foundation\apache-maven-3.1.1

3. Set Environment Variables.

The below screen can be obtained from My Computer –> Properties –> Advanced System Settings.

4       5

Create a User Variable – M2_HOME with value – D:\Program Files\Apache Foundation\apache-maven-3.1.1

Append the PATH under System Variable with a semi colon – D:\Program Files\Apache Foundation\apache-maven-3.1.1\bin

You can see in the below image that how I added value for PATH. You should put a semi colon to the existing value and paste the above path.

6

Once the Environment Variables are set. You can validate by putting :

> mvn –version command under DOS.

7

You are DONE with Maven set up !

How to Backup your Orkut ?

Hello Friends,

Orkut would be the first social media networking site for many people. It’s time to backup your memories.

Please click the below link and select Orkut alone to backup your timeline, albums etc … .. .

Google Takeout

orkut-pix

Click on – Next – and follow the archival procedure.

Hope it helped !

Eclipse – Failed to load the JNI shared library “C:/JDK/bin/client/jvm.dll”

Hello Team,

I found something interesting on configuring my new laptop for JAVA & Eclipse.

I followed the normal procedure and installed JAVA and Eclipse but when I tried launching Eclipse got the below error.

eclipse

Error Message – Failed to load the JNI shared Library !

Issue : The issue is caused due to the mismatch between the JAVA & Eclipse bit versions. I installed 64 bit jdk and tried launching Eclipse built for x86 version. :)

Resolution : Install the same version of JAVA & Eclipse too resolve the issue. Recommended version is x86.

Hope this helps !