Doctrine – How to print out the real sql, not just the prepared statement?

Doctrine is not sending a “real SQL query” to the database server : it is actually using prepared statements, which means : Sending the statement, for it to be prepared (this is what is returned by $query->getSql()) And, then, sending the parameters (returned by $query->getParameters()) and executing the prepared statements This means there is never … Read more

Difference Between One-to-Many, Many-to-One and Many-to-Many?

Looks like everyone is answering One-to-many vs. Many-to-many: The difference between One-to-many, Many-to-one and Many-to-Many is: One-to-many vs Many-to-one is a matter of perspective. Unidirectional vs Bidirectional will not affect the mapping but will make difference on how you can access your data. In Many-to-one the many side will keep reference of the one side. … Read more

How to persist a property of type List in JPA?

Use some JPA 2 implementation: it adds a @ElementCollection annotation, similar to the Hibernate one, that does exactly what you need. There’s one example here. Edit As mentioned in the comments below, the correct JPA 2 implementation is javax.persistence.ElementCollection @ElementCollection Map<Key, Value> collection; See: http://docs.oracle.com/javaee/6/api/javax/persistence/ElementCollection.html

Map enum in JPA with fixed values?

For versions earlier than JPA 2.1, JPA provides only two ways to deal with enums, by their name or by their ordinal. And the standard JPA doesn’t support custom types. So: If you want to do custom type conversions, you’ll have to use a provider extension (with Hibernate UserType, EclipseLink Converter, etc). (the second solution). … Read more

How to query between two dates using Laravel and Eloquent?

The whereBetween method verifies that a column’s value is between two values. $from = date(‘2018-01-01’); $to = date(‘2018-05-02’); Reservation::whereBetween(‘reservation_from’, [$from, $to])->get(); In some cases you need to add date range dynamically. Based on @Anovative’s comment you can do this: Reservation::all()->filter(function($item) { if (Carbon::now()->between($item->from, $item->to)) { return $item; } }); If you would like to add … Read more

What is an ORM, how does it work, and how should I use one? [closed]

Introduction Object-Relational Mapping (ORM) is a technique that lets you query and manipulate data from a database using an object-oriented paradigm. When talking about ORM, most people are referring to a library that implements the Object-Relational Mapping technique, hence the phrase “an ORM”. An ORM library is a completely ordinary library written in your language … Read more

Is there a way to call a stored procedure with Dapper?

In the simple case you can do: var user = cnn.Query<User>(“spGetUser”, new {Id = 1}, commandType: CommandType.StoredProcedure).First(); If you want something more fancy, you can do: var p = new DynamicParameters(); p.Add(“@a”, 11); p.Add(“@b”, dbType: DbType.Int32, direction: ParameterDirection.Output); p.Add(“@c”, dbType: DbType.Int32, direction: ParameterDirection.ReturnValue); cnn.Execute(“spMagicProc”, p, commandType: CommandType.StoredProcedure); int b = p.Get<int>(“@b”); int c = p.Get<int>(“@c”); … Read more

Performing Inserts and Updates with Dapper

We are looking at building a few helpers, still deciding on APIs and if this goes in core or not. See: https://code.google.com/archive/p/dapper-dot-net/issues/6 for progress. In the mean time you can do the following val = “my value”; cnn.Execute(“insert into Table(val) values (@val)”, new {val}); cnn.Execute(“update Table set val = @val where Id = @id”, new … Read more

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