It’s been ages since I have posted some sample code. It’s mainly because I don’t have time to collect and post sample code anymore. This once was a bit more challenging and googling wasn’t help much, so now that I have some time I though I would post some sample code that achieves batch inserts with spring data.

For example this link:
http://forum.spring.io/forum/spring-projects/data/118203-bulk-insert-with-crudrepository indicated that I had to manually get the session and iterate/flush (which was true when using Spring/Hibernate/JPA). But when using the CRUDRepository it appears it’s much simpler.

FULL CODE

Full code sample (maven project) can be found on github: https://github.com/cyrus13/anastasakis-net-sample-code/tree/master/spring-data-batch

You basically need to have the following elements:

  • Add: ?rewriteBatchedStatements=true to the end of the connectionstring.
  • Make sure you use a generator that supports batching in your entity. E.g.
@Id
@GeneratedValue(generator = "generator")
@GenericGenerator(name = "generator", strategy = "increment")
  • Use the: save(Iterable<S> paramIterable); method of the JpaRepository to save the data.
  • Use the: hibernate.jdbc.batch_size configuration.

RESULT

So enabling the query log in MySQL:

SET global general_log = 1;
SET global log_output = 'table';

we can see the following mysql code is executed:

SET autocommit=0;
select max(id) from ExampleEntity;
SHOW WARNINGS;
select @@session.tx_read_only;
insert into ExampleEntity (exampleText, id) values 
('de32bec8-1cf9-4f14-b816-0ab7a00b1539', 4),
('c0c85b32-eb2d-4a69-ade4-ac70ea94241c', 5);
commit;
SET autocommit=1;

Note: Don’t forget to stop logging statements into MySQL general log!

SET global general_log = 0;

I have a MacBook Pro (13-inch, Late 2011) with 8GB of RAM. As I need quite a few memory thirsty applications I have reached a point where 8GB is not enough. The official documentation of the Mac says that it supports up to 8GB. So I need to buy a new laptop?

Apparently not! It seems that the laptop supports 16GB of RAM, but not officially (from Apple). Crucial provides a system scanner, which scans your systems and suggests for compatible memory. It suggested a kit of 16GB memory. I have ordered it and I am waiting to install. The link for the scanner: http://eu.crucial.com/eur/en/systemscanner

Today I decided to update to OSX Yosemite. How much time would it take? 1 hour, 2hours? It appeared to get stuck to “one minute to finish” the installation for quite some time. During the upgrade process if you move the cursor to the top of the screen a menu will appear. One of the options is: “Show Log”. This option pops up a window that shows detailed information about the process.

In my case for around half an hour it was logging events like this:

 Nov 16 12:54:13 MacBook-Pro.lan OSInstaller[411]: (NodeOp) Move "/Volumes/Macintosh HD/Recovered Items/usr/local/texlive/2012/texmf-dist/source/latex/koma-script/doc/english/common-1.tex" -> "/Volumes/Macintosh HD/usr/local/texlive/2012/texmf-dist/source/latex/koma-script/doc/english" Final name: "common-1.tex" (Flags used: kFSFileOperationDefaultOptions,kFSFileOperationSkipSourcePermissionErrors,kFSFileOperationCopyExactPermissions,kFSFileOperationSkipPreflight,k_FSFileOperationSuppressConversionCopy)

It appears it was taking a lot of time processing the texlive files. I had installed texlive in the past, but i haven’t used it at least in a year. So, before upgrading to Yosemite make sure to delete any unwanted applications for a faster upgrade!

I have a Thomson TG585v8 router and I connect to a Cisco VPN using my Macbook running Mavericks. When I connect to the VPN all other devices in the house lose connectivity to the internet! I checked the router logs and I got quite a few errors like the following when connecting to the VPN:

UPnP action ‘AddPortMapping’ from ip (Undocumented UPNP error)

It is clearly and error related to the uPnP. So I disabled UPnp on the Thomson router and now everything works perfectly when I connect to the VPN.