Search Results

Search found 4565 results on 183 pages for 'nhibernate mapping'.

Page 82/183 | < Previous Page | 78 79 80 81 82 83 84 85 86 87 88 89  | Next Page >

  • Unable to execute native sql query

    - by Renjith
    I am developing an application with Spring and hibernate. In the DAO class, I was trying to execute a native sql as follows: SELECT * FROM product ORDER BY unitprice ASC LIMIT 6 OFFSET 0 But the system throws an exception. org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here org.springframework.orm.hibernate3.SpringSessionContext.currentSession(SpringSessionContext.java:63) org.hibernate.impl.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:544) com.dao.ProductDAO.listProducts(ProductDAO.java:15) com.dataobjects.impl.ProductDoImpl.listProducts(ProductDoImpl.java:26) com.action.ProductAction.showProducts(ProductAction.java:53) sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) application-context.xml is show below <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" p:location="/WEB-INF/jdbc.properties" /> <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource" p:driverClassName="${jdbc.driverClassName}" p:url="${jdbc.url}" p:username="${jdbc.username}" p:password="${jdbc.password}" /> <!-- Hibernate SessionFactory --> <!-- class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"--> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="dataSource"> <ref local="dataSource"/> </property> <property name="configLocation"> <value>WEB-INF/classes/hibernate.cfg.xml</value> </property> <property name="configurationClass"> <value>org.hibernate.cfg.AnnotationConfiguration</value> </property> <!-- <property name="annotatedClasses"> <list> <value>com.pojo.Product</value> <value>com.pojo.User</value> <value>com.pojo.UserLogin</value> </list> </property> --> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">${hibernate.dialect}</prop> <prop key="hibernate.show_sql">true</prop> </props> </property> </bean> <!-- User Bean definitions --> <bean name="/logincheck" class="com.action.LoginAction"> <property name="userDo" ref="userDo" /> </bean> <bean id="userDo" class="com.dataobjects.impl.UserDoImpl" > <property name="userDAO" ref="userDAO" /> </bean> <bean id="userDAO" class="com.dao.UserDAO" > <property name="sessionFactory" ref="sessionFactory" /> </bean> <bean name="/listproducts" class="com.action.ProductAction"> <property name="productDo" ref="productDo" /> </bean> <bean id="productDo" class="com.dataobjects.impl.ProductDoImpl" > <property name="productDAO" ref="productDAO" /> </bean> <bean id="productDAO" class="com.dao.ProductDAO" > <property name="sessionFactory" ref="sessionFactory" /> </bean> And DAO class is public class ProductDAO extends HibernateDaoSupport{ public List listProducts(int startIndex, int incrementor) { org.hibernate.Session session = getHibernateTemplate().getSessionFactory().getCurrentSession(); String queryString = "SELECT * FROM product ORDER BY unitprice ASC LIMIT 6 OFFSET 0"; List list = null; try{ session.beginTransaction(); org.hibernate.Query query = session.createQuery(queryString); list = query.list(); session.getTransaction().commit(); } catch(Exception e) { e.printStackTrace(); } finally { session.close(); } return list; } public List getProductCount() { String queryString = "SELECT COUNT(*) FROM Product"; return getHibernateTemplate().find(queryString); } } Any thoughts to fix it up?

    Read the article

  • Set creation and update time with Hibernate in Xml mappings

    - by Marco
    Hi, I'm using Hibernate with Xml mappings. I have an entity that has two fields creationDate and updateDate of type timestamp, that have to be filled with the current UTC time when the entity is persisted and updated. I know about the existence of the @PrePersist and @PreUpdate annotations, but i don't know how to use their equivalent in my Xml mappings. Again, i was wondering if Hibernate somehow supports natively the update and creation time set. Thanks

    Read the article

  • Help needed with Linq To Sql Query

    - by fearofawhackplanet
    I have the concept of valid/ordered transitions. So for example, it's not possible to move to status In progress from status Complete. Current and Next in table StatusTransition are FK (StatusType.Id). The Linq generator has created the following relations: Child Property Name: StatusTransitions1 Parent Property Name: StatusType1 Participating Properties: StatusType.Id -> StatusTransition.Next Child Property Name: StatusTransitions Parent Property Name: StatusType Participating Properties: StatusType.Id -> StatusTransition.Current I'm normally ok with Linq but I'm having difficulty getting the list of valid Next StatusTypes from the Current status. public List<StatusType> GetValidStatusTransitions(int statusId) { // trying to write something like the following // (obviously not correct) return _statusRepository .Where(s => s.Id == statusId) .Next.StatusTypes; }

    Read the article

  • How to create a "dependency graph" for IT assets

    - by p.marino
    One of my customers is trying to create an interactive "matrix" of interdependencies for the various applications used in their company (it's a travel&leisure company with around 2500 employees). The idea (still at the prototype stage) is to create a sort of Map, based on Visio or similar tool, which traces the communication and interdependencies between all the IT assets in the company, so that when someone asks for a change they can get an overview of the impacts. This was mentioned in a casual setting and it will not be my responsability to directly work on this, but I did contribute the little I know already in terms of vaguely related methodologies (Zachman Framework). I'd like to hear from the people in here if they know of methodologies, or tools, that may help this kind of effort, and if they have any specific experience to contribute. I'll digest the answers and send the result back to my customer, hoping this may be of some help with their task (which I consider a bit visionary and prone to all the pitfalls of any documentation project, but still well worth pursuing).

    Read the article

  • Java JPA @OneToMany neededs to reciprocate @ManyToOne?

    - by bguiz
    Create Table A ( ID varchar(8), Primary Key(ID) ); Create Table B ( ID varchar(8), A_ID varchar(8), Primary Key(ID), Foreign Key(A_ID) References A(ID) ); Given that I have created two tables using the SQL statements above, and I want to create Entity classes for them, for the class B, I have these member attributes: @Id @Column(name = "ID", nullable = false, length = 8) private String id; @JoinColumn(name = "A_ID", referencedColumnName = "ID", nullable = false) @ManyToOne(optional = false) private A AId; In class A, do I need to reciprocate the many-to-one relationship? @Id @Column(name = "ID", nullable = false, length = 8) private String id; @OneToMany(cascade = CascadeType.ALL, mappedBy = "AId") private List<B> BList; //<-- Is this attribute necessary? Is it a necessary or a good idea to have a reciprocal @OneToMany for the @ManyToOne? If I make the design decision to leave out the @OneToMany annotated attribute now, will come back to bite me further down.

    Read the article

  • When does it make sense to use a map?

    - by kiwicptn
    I am trying to round up cases when it makes sense to use a map (set of key-value entries). So far I have two categories (see below). Assuming more exist, what are they? Please limit each answer to one unique category and put up an example. Property values (like a bean) age -> 30 sex -> male loc -> calgary Presence, with O(1) performance peter -> 1 john -> 1 paul -> 1

    Read the article

  • To Interface or Not?: Creating a polymorphic model relationship in Ruby on Rails dynamically..

    - by Globalkeith
    Please bear with me for a moment as I try to explain exactly what I would like to achieve. In my Ruby on Rails application I have a model called Page. It represents a web page. I would like to enable the user to arbitrarily attach components to the page. Some examples of "components" would be Picture, PictureCollection, Video, VideoCollection, Background, Audio, Form, Comments. Currently I have a direct relationship between Page and Picture like this: class Page < ActiveRecord::Base has_many :pictures, :as => :imageable, :dependent => :destroy end class Picture < ActiveRecord::Base belongs_to :imageable, :polymorphic => true end This relationship enables the user to associate an arbitrary number of Pictures to the page. Now if I want to provide multiple collections i would need an additional model: class PictureCollection < ActiveRecord::Base belongs_to :collectionable, :polymorphic => true has_many :pictures, :as => :imageable, :dependent => :destroy end And alter Page to reference the new model: class Page < ActiveRecord::Base has_many :picture_collections, :as => :collectionable, :dependent => :destroy end Now it would be possible for the user to add any number of image collections to the page. However this is still very static in term of the :picture_collections reference in the Page model. If I add another "component", for example :video_collections, I would need to declare another reference in page for that component type. So my question is this: Do I need to add a new reference for each component type, or is there some other way? In Actionscript/Java I would declare an interface Component and make all components implement that interface, then I could just have a single attribute :components which contains all of the dynamically associated model objects. This is Rails, and I'm sure there is a great way to achieve this, but its a tricky one to Google. Perhaps you good people have some wise suggestions. Thanks in advance for taking the time to read and answer this.

    Read the article

  • EntityFramework: Access dabase-column using user defined Type

    - by Nils
    I "inherited" an old Database where dates are stored as Int32 values (times too, but dates shall suffice for this example) i.e. 20090101 for Jan. 1st 2009. I can not change the schema of this database because it is still accessed by the old programs. However I want to write a new program using EF as the O/R-M. Now I'd love to have DateTime-Values in my Model. Is there a way to write a custom type and use this as a Type in the EF-Model. Something like a Type "OldDate" with properties: DatabaseValue : Int23 Value : DateTime (specifying the date-part whereas the time-part is always 0:00:00) Is something like this possible with the EF-Model ?

    Read the article

  • Parent-Child relation while using object data source

    - by Saba
    Hello guys I am experiencing with a class generator I've written, which generates a class for each table in database with each table field as a property and such. Before that, I used to add a typed dataset to the project and add some tables to it. It automatically detected the relationship between tables and when I added a parent table as data source of a datagrid, I could add another datagrid and use the foreing key data member of it's bindingsource to fill it, and when someone moved the focus on parent datagrid, the data in child datagrid would change accordingly. Now that I have my classes, I add an object as data source for my 2 datagrids, but obviously it doesn't detect a parent child relation. But It'd really help if I could have that foreign key relation in my object datasources. Is there any way to have that relation in object datasource?

    Read the article

  • Creating relationship between two model instances

    - by Lowgain
    This is probably pretty simple, but here: Say I've got two models, Thing and Tag class Thing < ActiveRecord::Base has_and_belongs_to_many :tags end class Tag < ActiveRecord::Base has_and_belongs_to_many :things end And I have an instance of each. I want to link them. Can I do something like: @thing = Thing.find(1) @tag = Tag.find(1) @thing.tags.add(@tag) If not, what is the best way to do this? Thanks!

    Read the article

  • hibernate modeling relationships managed through an intermediate table

    - by shikarishambu
    I have a datamodel that has an intermediate table to manage relationships between entities. For example, tables Person and Organization are related through the Relationship table Party (table) - ID Person (table) - ID (references Party.ID) - name Organization (table) -ID (references Party.ID) -name Relationship (table) -ID (PK) -type (references relationshiptype lookup) -fromID (references Party.ID) -ToID (references Party.ID) -fromDate -ToDate Type+fromID+ToID+fromDate+ToDate is guaranteed to be unique. How do I manage this using hibernate? TIA

    Read the article

  • How to add an additional field to a queryset?

    - by Mark
    I've got a list of affiliates (users who have referred someone to the site): affiliates = User.objects.annotate(referral_count=Count('referrals')).filter(referral_count__gt=0) And a count of the number of users each affiliate has referred within a time frame: new_users = User.objects.filter(date_joined__gt=sd, date_joined__lte=ed) new_referrals = User.objects.filter(referrals__user__in=new_users).annotate(referral_count=Count('referrals')) How can I do something like new_referrals['affiliate.username'].referral_count from within my template? Note that this is not just a syntax issue, I also need to index new_referrals somehow so that I'm able to do this. Either this, or if I can somehow add a new_referral_count to the first query, that'd work too.

    Read the article

  • How to map a Entity Data Model conceptual model property to a storage model column using the "Serial

    - by codekaizen
    I have a conceptual model in EDM where one of the entities has a property which is essentially a big value object whose properties aren't really useful as columns in the datamodel. I'd like to apply the Serialized LOB pattern to it so that I can fit it into a 192 byte binary column. How do I map this in the EDM v4? Is it even possible at this time? Actually, is it possible in any ORM?

    Read the article

  • rails: has_many :through + polymorphism validation?

    - by ramonrails
    I am trying to achieve this. Any hints? A project has many users through join model A user has many projects through join model Admin class inherits User class. It also has some Admin specific stuff. Admin like inheritance for Supervisor and Operator Project has one Admin, One supervisor and many operators. Now I want to 1. submit data for project, admin, supervisor and operator in a single project form 2. validate all and show errors on the project form. Project has_many :users, :through = :projects_users User has_many :projects, :through = :projects_users ProjectsUser = :id integer, :user_id :integer, :project_id :integer, :user_type :string ProjectUser belongs_to :project, belongs_to :user, :polymorphic = true Admin < User Supervisor < User Operator < User Is the approach correct? Any and all suggestions are welcome.

    Read the article

  • How Do I get City State Zip in MVC 3 URL Route without writing a controller for every state and actions for each city

    - by OpTech Marketing
    I have the need to have the urls in my bosses application look like: http://domain.com/Texas/Dallas/72701 However, I don't want to write a controller for every state and an action for every city. routes.MapRoute( "DrillDown", // Route name "{controller}/{action}/{ZipId}", new { controller = "State", action = "City", ZipId = UrlParameter.Optional} // Parameter defaults Can someone help me write a pattern for the routes that will accept State/City/Zip without destroying the ability for me to have regular routes with controller/Action/Param ? Looking all over and can't find any direction.

    Read the article

  • Finding City and Zip Code for a Location

    - by Kristopher Johnson
    Given a latitude and longitude, what is the easiest way to find the name of the city and the US zip code of that location. (This is similar to http://stackoverflow.com/questions/23572/latitude-longitude-database, except I want to convert in the opposite direction.) Related question: http://stackoverflow.com/questions/158557/get-street-address-at-latlong-pair

    Read the article

  • Best way to model Customer <--> Address

    - by Jen
    Every Customer has a physical address and an optional mailing address. What is your preferred way to model this? Option 1. Customer has foreign key to Address Customer (id, phys_address_id, mail_address_id) Address (id, street, city, etc.) Option 2. Customer has one-to-many relationship to Address, which contains a field to describe the address type Customer (id) Address (id, customer_id, address_type, street, city, etc.) Option 3. Address information is de-normalized and stored in Customer Customer (id, phys_street, phys_city, etc. mail_street, mail_city, etc.) One of my overriding goals is to simplify the object-relational mappings, so I'm leaning towards the first approach. What are your thoughts?

    Read the article

  • What SQL ORM may i use to replace this old code

    - by acidzombie24
    Sorry since this question is specific to my problem. While learning reflections i did a mini SQL ORM in a week then minor tweaks while using it for another week. Since it has very little work put into it, its really only compatibility with sqlite. I havent had problems with the code so far but i would like to port it to something that supports TSQL or MySql. The example code is here which is outdated but has the most used functions in my class. What library can i port that code over too with the smallest about of pain. Note that it must support foreign keys.

    Read the article

  • How can I avoid setting some columns if others haven't changed, when working with Linq To SQL?

    - by Patrick Szalapski
    In LINQ to SQL, I want to avoid setting some columns if others haven't changed? Say I have dim row = (From c in dataContext.Customers Where c.Id = 1234 Select c).Single() row.Name = "Example" ' line 3 dataContext.SubmitChanges() ' line 4 Great, so LINQ to SQL fetches a row, sets the name to "Example" in memory, and generates an update SQL query only when necessary--that is, no SQL will be generated if the customer's name was already "Example". So suppose on line 3, I want to detect if row has changed, and if so, set row.UpdateDate = DateTime.Now. If row has not changed, I don't want to set row.UpdateDate so that no SQL is generated. Is there any good way to do this?

    Read the article

  • rais belong_to which class to choose

    - by Small Wolf
    There is a model relation like this. class A belongs_to :ref_config,:class_name => 'User' end My question is : the A has a attribute named flag, now i want to create a function like this: if flag == 1, I want the class A like this belongs_to :ref_config,:class_name => 'Department and if flag == 2, i want the class A like this belongs_to :ref_config,:class_name => 'User' How can I implement the function Thank you!

    Read the article

< Previous Page | 78 79 80 81 82 83 84 85 86 87 88 89  | Next Page >