What Java ORM do you prefer, and why? [closed]

I have stopped using ORMs. The reason is not any great flaw in the concept. Hibernate works well. Instead, I have found that queries have low overhead and I can fit lots of complex logic into large SQL queries, and shift a lot of my processing into the database. So consider just using the JDBC … Read more

Entity Framework Code First – two Foreign Keys from same table

Try this: public class Team { public int TeamId { get; set;} public string Name { get; set; } public virtual ICollection<Match> HomeMatches { get; set; } public virtual ICollection<Match> AwayMatches { get; set; } } public class Match { public int MatchId { get; set; } public int HomeTeamId { get; set; } public … Read more

Get Specific Columns Using “With()” Function in Laravel Eloquent

Well I found the solution. It can be done one by passing a closure function in with() as second index of array like Post::query() ->with([‘user’ => function ($query) { $query->select(‘id’, ‘username’); }]) ->get() It will only select id and username from other table. I hope this will help others. Remember that the primary key (id … Read more

Laravel – Eloquent “Has”, “With”, “WhereHas” – What do they mean?

With with() is for eager loading. That basically means, along the main model, Laravel will preload the relationship(s) you specify. This is especially helpful if you have a collection of models and you want to load a relation for all of them. Because with eager loading you run only one additional DB query instead of … Read more

Default value in Doctrine

<?php /** * @Entity */ class myEntity { /** * @var string * * @ORM\Column(name=”myColumn”, type=”integer”, options={“default” : 0}) */ private $myColumn; … } Note that this uses SQL DEFAULT, which is not supported for some fields like BLOB and TEXT.

What’s the best strategy for unit-testing database-driven applications?

I’ve actually used your first approach with quite some success, but in a slightly different ways that I think would solve some of your problems: Keep the entire schema and scripts for creating it in source control so that anyone can create the current database schema after a check out. In addition, keep sample data … Read more

Hibernate show real SQL [duplicate]

Can I see (…) the real SQL If you want to see the SQL sent directly to the database (that is formatted similar to your example), you’ll have to use some kind of jdbc driver proxy like P6Spy (or log4jdbc). Alternatively you can enable logging of the following categories (using a log4j.properties file here): log4j.logger.org.hibernate.SQL=DEBUG … Read more

Conversion of a datetime2 data type to a datetime data type results out-of-range value

Short Answer This can happen if you do not initialize a value to a DateTime field; the field does not accept NULL values, and it’s a value type, so the default value of the non-nullable DateTime type will be used. Setting the value fixed it for me! Long Answer The value of default(DateTime) is DateTime.MinValue … Read more

How to print a query string with parameter values when using Hibernate

You need to enable logging for the the following categories: org.hibernate.SQL   – set to debug to log all SQL DML statements as they are executed org.hibernate.type – set to trace to log all JDBC parameters So a log4j configuration could look like: # logs the SQL statements log4j.logger.org.hibernate.SQL=debug # Logs the JDBC parameters passed to … Read more

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