Monday, January 26, 2009

MySQL Dump and Recreate

Here's a little post so I don't forget to dump and recreate a MySQL database.

To dump a database:
$ mysqldump -uroot -ppassword mydb > mydb.mysql
To recreate the database:
$ mysqladmin -uroot -ppassword drop mydb
$ mysqladmin -uroot -ppassword create mydb
$ mysql -uroot -ppassword mydb < mydb.mysql

Friday, January 23, 2009

/usr/bin/ld: cannot find -lperl

I was trying to install pp, the Perl PAR Packager:
$ sudo cpan pp
I got this error:
/usr/bin/ld: cannot find -lperl
collect2: ld returned 1 exit status
make[1]: *** [par] Error 1
make[1]: Leaving directory `/home/prystasj/.cpan/build/PAR-Packer-0.982-zX8GIO/myldr'
make: *** [subdirs] Error 2
SMUELLER/PAR-Packer-0.982.tar.gz
/usr/bin/make -- NOT OK
Running make test
Can't test without successful make
Running make install
Make had returned bad status, install seems impossible
I saw a suggestion to install libperl-dev, but I had that package already up-to-date.
By changing this symlink in /usr/lib from:
lrwxrwxrwx 1 root root 15 2009-01-23 15:28 /usr/lib/libperl.so -> libperl.so.5.10
To:
lrwxrwxrwx 1 root root 15 2009-01-23 15:28 /usr/lib/libperl.so -> libperl.so.5.10.0
I was able to install pp:
$ which pp
/usr/local/bin/pp

Wednesday, January 7, 2009

JPA: Retrieving ID of Recently Persisted Object

Using JPA with an orm.xml, I was having trouble retrieving the primary key (id) of a recently persisted object. The entity in my orm.xml:

<entity class="Foo" name="Foo" access="FIELD">
<table name="Foo"/>
<attributes>
<id name="id">
<column name="ID" nullable="false"/>
<generated-value strategy="SEQUENCE"/>
</id>
...
</table>
</entity>
The relevant MySQL for the table:
CREATE TABLE FOO
(
ID INT NOT NULL AUTO_INCREMENT,
...
PRIMARY KEY(ID)
)
Regardless of whether or not the id property was null or not, it was not updated after the following call to persist():
Foo foo = new Foo();
getJpaTemplate().persist(foo);
if (logger.isDebugEnabled())
logger.debug(foo.getId()) // null

Adding a call to flush() however ended up giving me the id:
Foo foo = new Foo();
getJpaTemplate().persist(foo);
getJpaTemplate().flush();
if (logger.isDebugEnabled())
logger.debug(foo.getId()) // outputs the assigned id
I'm not sure why the flush() was necessary. A similar issue is also discussed here: Spring Forums Post.