orm

Control sort order of Hibernate EnumType.STRING properties

淺唱寂寞╮ 提交于 2020-01-13 09:27:06
问题 Currently, my project uses @Enumerated(EnumType.ORDINAL) , so when I sort by this column, it is ordering based on the order in the enum , which works fine. But I need to add some additional values to the enum , which need to be inserted at different locations in the list of enum values and can't be just added to the bottom to maintain the correct sort order. If I do this, my database will be messed up. I'll have to write some scripts to translate all these ordinal values to the correct new

Is it illegitimate to name an JPA entity “Group”?

会有一股神秘感。 提交于 2020-01-13 09:14:06
问题 I'm developing a JEE6-application, using JPA 2.0 and Hibernate 3.5.2-Final as the Provider (and MySQL 5.1.41). My Application Server is Glassfish V3.0.1. I already have a working CRUD-app with some entities and relationships. Now i added an (really simple) entity with the name "Group". The entity class looks like this: package model //Imports... @Entity public class Group { @Id @GeneratedValue private Long id; @NotNull private String name; //Getters and Setters } Of course I also added it to

How to model this situation in ORM (NHibernate)?

江枫思渺然 提交于 2020-01-13 07:08:14
问题 I've always taken a data centric approach to web apps, and so the paradigm change involved when taking a pure OO approach using ORMs is still not completely natural to me, and evey now and then something ostensibly simple is not obvious. Can someone please point me into the right direction of how to correctly model this situation in an ORM (Specifically NHibernate). The situation: There are many Users, Many Items, users may rate Items. In a data centric/relational approach it would look like

ORM,XSS攻击

与世无争的帅哥 提交于 2020-01-13 06:41:08
1. ORM 1.1 对表的基本查 # 单表的查 # 1、查询所有 res = Class.objects.all() # QuerySet对象,(列表套对象) print(res) # <QuerySet [<Class: Class object>, <Class: Class object>, <Class: Class object>, <Class: Class object>]> for row in res: print(row.id, row.cname) # 2. 指定字段查询 values, value_list res = Class.objects.values('cname').all() # QuerySet对象,(列表套字典) print(res) # <QuerySet [{'cname': 'pyton8期'}, {'cname': 'pyton9期'}, {'cname': 'pyton10期'}, {'cname': 'pyton11期'}]> res = Class.objects.values_list('cname').all() # QuerySet对象,(列表套元组) # print(res) # <QuerySet [('pyton8期',), ('pyton9期',), ('pyton10期',), ('pyton11期',)]>

Cant connect to localhost database with Sequelize (nodejs)

蹲街弑〆低调 提交于 2020-01-13 05:53:49
问题 I am using SequelizeJS to connect and talk to my database which is on my localhost (MAMP). However, whenever I try to execute a query, I keep getting this error: ECONNREFUSED . I double checked the port number of MySQL and the host name, which are 3306 and localhost. I pretty much followed the guide that is on their site. Here is some of my code: var sequelize = new mysql('partythump', 'root', 'mysqlroot', { host: 'localhost', port: 3306, timestamps: false }); var parties = sequelize.define(

How to list out all items in a nested table in Laravel

你离开我真会死。 提交于 2020-01-13 05:39:11
问题 I am using Laravel's Eloquent ORM and I'm having trouble eager loading items for display. Here is the scenario: Users follow Blogs Blogs have Posts I have a database table named Relationships, this table is used to store the User ID and the Blog ID to show which User is following which Blog. I have a table for Blogs describing the Blog and I have a table for Posts. The Relationships table would be my pivot table to connect the Users with the Blogs tables together. Now, I need to list out all

How to create/call a sql view in Hibernate

99封情书 提交于 2020-01-13 04:29:07
问题 Here is the view created in document.hbm.xml <database-object> <create><![CDATA[CREATE VIEW docView AS SELECT * from document; GO]]></create> <drop>DROP VIEW docView</drop> <dialect-scope name='org.hibernate.dialect.SQLServerDialect' /> </database-object> Now how to call this view in my method Tried calling like this Session session = sessFactory.openSession(); Query query = session.createSQLQuery("docView"); List<?> list = query.list(); Ended up with Caused by: java.sql.SQLException: The

Hibernate执行原生SQL返回List<Map>类型结果集

a 夏天 提交于 2020-01-13 02:27:13
我是学java出身的,web是我主要一块; 在做项目的时候最让人别扭的就是hibernate查询大都是查询出List<T>(T指代对应实体类)类型 如果这时候我用的联合查询,那么返回都就是List<Object[]> , 这样的结果集让我苦恼了很久, 于是我萌发了使用spring提供的JdbcTemlate来 查询出 List<Map<String,Object>>的念头, 方法虽然可行,可惜的是spring偌大一个框架,居然不提供jdbc分页。。。。 无奈之下我又重新回归hibernate,找了很久,终于发现hibernate原来是可以查询出List<Map<String,Object>>类型的结果集 1.2、query.setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP); Query 和 SQLQuery都可以使用别名,将查询出来的记录转化成为map SQLQuery执行出来是{name1: value1, name2: value2} 但是Query 例如语句: select o.name1, o.name2 from Object o 执行出来的却不是想象中的那样而且{0:value1, 1: value2} import org.hibernate.criterion.CriteriaSpecification

.NET ORMs, immutable value objects, structs, default constructors, and readonly properties

喜欢而已 提交于 2020-01-12 18:47:20
问题 I am just getting started with .NET ORMs, to the point where I haven't even decided between Entity Framework and NHibernate. But in both cases, I'm running into a problem in that they seem to want me to compromise the integrity of my domain model in various ways, especially on finer points of C# object design. This is one of several questions on the subject. I am very used to enforcing immutability on appropriate properties with a pattern that looks like this: public class Foo { private

.NET ORMs, immutable value objects, structs, default constructors, and readonly properties

末鹿安然 提交于 2020-01-12 18:47:13
问题 I am just getting started with .NET ORMs, to the point where I haven't even decided between Entity Framework and NHibernate. But in both cases, I'm running into a problem in that they seem to want me to compromise the integrity of my domain model in various ways, especially on finer points of C# object design. This is one of several questions on the subject. I am very used to enforcing immutability on appropriate properties with a pattern that looks like this: public class Foo { private