Spring-Data JPA: save new entity referencing existing one

I had a similar issue where I was trying to save an new entity object with an already saved entity object inside. What I did was implemented Persistable< T > and implemented isNew() accordingly. public class MyEntity implements Persistable<Long> { public boolean isNew() { return null == getId() && subEntity.getId() == null; } Or you … Read more

AngularJS: Change hash and route without completely reloading controller

Had the very same challange, Found a hack in another StackOverflow response that did the trick Fairly clean solution – all I did was to add these lines to the controller that sets $location.path: var lastRoute = $route.current; $scope.$on(‘$locationChangeSuccess’, function(event) { $route.current = lastRoute; }); ..and made sure $route in injected into the controller of … Read more

Finding image type from NSData or UIImage

If you have NSData for the image file, then you can guess at the content type by looking at the first byte: + (NSString *)contentTypeForImageData:(NSData *)data { uint8_t c; [data getBytes:&c length:1]; switch (c) { case 0xFF: return @”image/jpeg”; case 0x89: return @”image/png”; case 0x47: return @”image/gif”; case 0x49: case 0x4D: return @”image/tiff”; } return … Read more

JPA EntityManager: Why use persist() over merge()?

Either way will add an entity to a PersistenceContext, the difference is in what you do with the entity afterwards. Persist takes an entity instance, adds it to the context and makes that instance managed (i.e. future updates to the entity will be tracked). Merge returns the managed instance that the state was merged with. … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)