Search Results

Search found 222 results on 9 pages for 'pojo'.

Page 2/9 | < Previous Page | 1 2 3 4 5 6 7 8 9  | Next Page >

  • Force Hibernate To Save A Specific POJO

    - by user1695626
    I have some code calling a webservice and it returns an id. I am saving this id in the database using hibernate. I have a filter that opens the session and commits it, rolling back when any exception occurs within the contained code. Since there is no way to get back the id returned by the webservice I would like to save this in the database EVEN if there is an exception that occurred later on in the code. Is there anyway to do this using the same session?

    Read the article

  • XStream or Simple

    - by Adeel Ansari
    I need to decide on which one to use. My case is pretty simple. I need to convert a simple POJO/Bean to XML, and then back. Nothing special. One thing I am looking for is it should include the parent properties as well. Best would be if it can work on super type, which can be just a marker interface. If anyone can compare these two with cons and pros, and which thing is missing in which one. I know that XStream supports JSON too, thats a plus. But Simple looked simpler in a glance, if we set JSON aside. Whats the future of Simple in terms of development and community? XStream is quite popular I believe, even the word, "XStream", hit many threads on SO. Thanks.

    Read the article

  • Hibernate generate POJOs with Equals

    - by jschoen
    We are using hibernate in a new project where we use the hibernate.reveng.xml to create our *.hbm.xml files and POJOs after that. We want to have equals methods in each of our POJOs. I found that you can use <meta attribute="use-in-equals">true</meta> in your hbm files to mark which properties to use in the equals. But this would mean editing alot of files, and then re-editing the files again in the future if/when we modify tables or columns in our DB. So I was wondering if there is a way to place which properties to use in the equals method for each pojo(table) in the hibernate.reveng.xml file?

    Read the article

  • Parsing JSON to XML using net.sf.json (java)

    - by Castanho
    Hi guys, I'm parsing a generic JSON to a XML using net.sf.json. (I'm not using POJO Obj in the conversion) When dealing with vectors I'm receiving: <root> <entry> <Id>1</accountId> <Items> <e> <cost>0.1</cost> <debit>0.1</debit> </e> <e> <cost>0.1</cost> <debit>0.1</debit> </e> </Items> </entry> </root> When the correct for my point of view should be: <root> <entry> <accountId>1</accountId> <Items> <cost>0.1</cost> <debit>0.1</debit> </Items> <Items> <cost>0.2</cost> <debit>0.2</debit> </Items> </entry> </root> Do anyone have used this lib and could help me? Any tips could help! Thanks in advance

    Read the article

  • JUnit tests for POJOs

    - by Ryan Thames
    I work on a project where we have to create unit tests for all of our simple beans (POJOs). Is there any point to creating a unit test for POJOs if all they consist of is getters and setters? Is it a safe assumption to assume POJOs will work about 100% of the time? Duplicate of - Should @Entity Pojos be tested? See also Is it bad practice to run tests on a DB instead of on fake repositories? Is there a Java unit-test framework that auto-tests getters and setters?

    Read the article

  • Is dependency injection possible for JSP beans?

    - by kazanaki
    This may be a long shot question.. I am working on an application that is based on JSP/Javascript only (without a Web framework!) Is there a way to have depencency injection for JSP beans? By jsp beans I mean beans defined like this <jsp:useBean id="cart" scope="session" class="session.Carts" /> Is there a way/library/hack to intercept the bean creation so that when "cart" is referenced for the first time, some some of injection takes place? Can I define somewhere a "listener" for JSP beans (like you can do for JSF beans for example)? I am free to do anything I want in the back-end, but I cannot add a web framework in the front-end (Don't ask!)

    Read the article

  • Hibernate many-to-many mapping not saved in pivot table

    - by vincent
    I having problems saving many to many relationships to a pivot table. The way the pojos are created is unfortunately a pretty long process which spans over a couple of different threads which work on the (to this point un-saved) object until it is finally persisted. I associate the related objects to one another right after they are created and when debugging I can see the List of related object populated with their respective objects. So basically all is fine to this point. When I persist the object everything get saved except the relations in the pivot table. mapping files: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping package="com.thebeansgroup.jwinston.plugin.orm.hibernate.object"> <class name="ShowObject" table="show_object"> <id name="id"> <generator class="native" /> </id> <property name="name" /> <set cascade="all" inverse="true" name="venues" table="venue_show"> <key column="show_id"/> <many-to-many class="VenueObject"/> </set> </class> </hibernate-mapping> and the other <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping package="com.thebeansgroup.jwinston.plugin.orm.hibernate.object"> <class name="VenueObject" table="venue_object"> <id name="id"> <generator class="native"/> </id> <property name="name"/> <property name="latitude" type="integer"/> <property name="longitude" type="integer"/> <set cascade="all" inverse="true" name="shows" table="venue_show"> <key column="venue_id"/> <many-to-many class="ShowObject"/> </set> </class> </hibernate-mapping> pojos: public class ShowObject extends OrmObject { private Long id; private String name; private Set venues; public ShowObject() { } public Long getId() { return id; } public void setId(Long id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public Set getVenues() { return venues; } public void setVenues(Set venues) { this.venues = venues; } } and the other: public class VenueObject extends OrmObject { private Long id; private String name; private int latitude; private int longitude; private Set shows = new HashSet(); public VenueObject() { } @Id @GeneratedValue(strategy = GenerationType.AUTO) public Long getId() { return id; } public void setId(Long id) { this.id = id; } public int getLatitude() { return latitude; } public void setLatitude(int latitude) { this.latitude = latitude; } public int getLongitude() { return longitude; } public void setLongitude(int longitude) { this.longitude = longitude; } public String getName() { return name; } public void setName(String name) { this.name = name; } public Set getShows() { return shows; } public void setShows(Set shows) { this.shows = shows; } } Might the problem be related to the lack of annotations?

    Read the article

  • SQL RDBMS : one query or multiple calls

    - by None None
    After looking around the internet, I decided to create DAOs that returned objects (POJOs) to the calling business logic function/method. For example: a Customer object with a Address reference would be split in the RDBMS into two tables; Customer and ADDRESS. The CustomerDAO would be in charge of joining the data from the two tables and create both an Address POJO and Customer POJO adding the address to the customer object. Finally return the fulll Customer POJO. Simple, however, now i am at a point where i need to join three or four tables and each representing an attribute or list of attributes for the resulting POJO. The sql will include a group by but i will still result with multiple rows for the same pojo, because some of the tables are joining a one to many relationship. My app code will now have to loop through all the rows trying to figure out if the rows are the same with different attributes or if the record should be a new POJO. Should I continue to create my daos using this technique or break up my Pojo creation into multiple db calls to make the code easier to understand and maintain?

    Read the article

  • Redirect to show ModelAndView from another Controller - (Spring 3 MVC, Hibernate 3)???

    - by Mimi
    How exactly can I trigger display of a model and view from another model and view’s controller? [B][COLOR="Blue"]HTTP Request View -- HttpRequestController POST - new HttpResponse POJO and a string of the POJO in XML as an Http Response msg to be sent back to the Requestor --[/COLOR][/B] [B][COLOR="Red"][/COLOR][/B] I have HttpRequestController() to handle a POST message with data from an input Form and populated an HttpRequest POJO with it. An HttpResponse POJO is composed and persisted along with the HttpRequest to a Db. I made this HttResponse POJO an XML string as the @Responsebody to be sent back by the HttpRequestController() (as an actual HTTP Response message with header and body) and I want to present this HttpResponse POJO in a View. I tried different things, none worked and I could not find a similar example anywhere.

    Read the article

  • Beyond the @Produces annotation, how does Jersey (JAX-RS) know to treat a POJO as a specific mime ty

    - by hal10001
    I see a lot of examples for Jersey that look something like this: public class ItemResource { @GET @Path("/items") @Produces({"text/xml", "application/json"}) public List<Item> getItems() { List<Item> items = new ArrayList<Item>(); Item item = new Item(); item.setItemName("My Item Name!"); items.add(item); return items; } } But then I have trouble dissecting Item, and how Jersey knows how to translate an Item to either XML or JSON. I've seen very basic examples that just return a String of constructed HTML or XML, which makes more sense to me, but I'm missing the next step. I looked at the samples, and one of them stood out (the json-from-jaxb sample), since the object was marked with these types of annotations: @XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "", propOrder = { "flight" }) @XmlRootElement(name = "flights") I'm looking for tutorials that cover this "translation" step-by-step, or an explanation here of how to translate a POJO to output as a specific mime type. Thanks!

    Read the article

  • How to map a property for HQL usage only (in Hibernate)?

    - by ManBugra
    i have a table like this one: id | name | score mapped to a POJO via XML with Hibernate. The score column i only need in oder by - clauses in HQL. The value for the score column is calculated by an algorithm and updated every 24 hours via SQL batch process (JDBC). So i dont wanna pollute my POJO with properties i dont need at runtime. For a single column that may be not a problem, but i have several different score columns. Is there a way to map a property for HQL use only? For example like this: <property name="score" type="double" ignore="true"/> so that i still can do this: from Pojo p order by p.score but my POJO implementation can look like this: public class Pojo { private long id; private String name; // ... } No Setter for score provided or property added to implementation. using the latest Hibernate version for Java.

    Read the article

  • How do I make JPA POJO classes + Netbeans forms play well together?

    - by Zak
    I started using netbeans to design forms to edit the instances of various classes I have made in a small app I am writing. Basically, the app starts, an initial set of objects is selected from the DB and presented in a list, then an item in the list can be selected for editing. When the editor comes up it has form fields for many of the data fields in the class. The problem I run into is that I have to create a controller that maps each of the data elements to the correct form element, and create an inordinate number of small conversion mapping lines of code to convert numbers into strings and set the correct element in a dropdown, then another inordinate amount of code to go back and update the underlying object with all the values from the form when the save button is clicked. My question is; is there a more directly way to make the editing of the form directly modify the contents of my class instance? I would like to be able to have a default mapping "controller" that I can configure, then override the getter/setter for a particular field if needed. Ideally, there would be standard field validation for things like phone numbers, integers, floats, zip codes, etc... I'm not averse to writing this myself, I would just like to see if it is already out there and use the right tool for the right job.

    Read the article

  • Deleting a resource in a Cucumber (Capybara) step doesn't work

    - by Josiah Kiehl
    Here is my Scenario: Scenario: Delete a match Given pojo is logged in And there is a match with the following: | game_id | 1 | | name | Game del Pojo | | date_and_time | 2010-02-23 17:52:00 | | players | 2 | | teams | 2 | | comment | This is an awesome comment | | user_id | 1 | And I am on the show match 1 page And show me the page When I follow "Delete" And I follow "Yes, delete it" Then there should not be a match with the following: | game_id | 1 | | name | Game del Pojo | | date_and_time | 2010-02-23 17:52:00 | | players | 2 | | teams | 2 | | comment | This is an awesome comment | | user_id | 1 | If I walk through these steps manually, they work. When I click the confirmation: Yes, delete it, then the match is deleted. Cucumber, however, fails to delete the record and the last step fails. And I follow "Yes, delete it" # features/step_definitions/web_steps.rb:32 Then there should not be a match with the following: # features/step_definitions/match_steps.rb:8 | game_id | 1 | | name | Game del Pojo | | date_and_time | 2010-02-23 17:52:00 | | players | 2 | | teams | 2 | | comment | This is an awesome comment | | user_id | 1 | <nil> expected but was <#<Match id: 1, name: "Game del Pojo", date_and_time: "2010-02-23 17:52:00", teams: 2, created_at: "2010-03-02 23:06:33", updated_at: "2010-03-02 23:06:33", comment: "This is an awesome comment", players: 2, game_id: 1, user_id: 1>>. (Test::Unit::AssertionFailedError) /usr/lib/ruby/1.8/test/unit/assertions.rb:48:in `assert_block' /usr/lib/ruby/1.8/test/unit/assertions.rb:495:in `_wrap_assertion' /usr/lib/ruby/1.8/test/unit/assertions.rb:46:in `assert_block' /usr/lib/ruby/1.8/test/unit/assertions.rb:83:in `assert_equal' /usr/lib/ruby/1.8/test/unit/assertions.rb:172:in `assert_nil' ./features/step_definitions/match_steps.rb:22:in `/^there should (not)? be a match with the following:$/' features/matches.feature:124:in `Then there should not be a match with the following:' Any clue how to debug this? Thanks!

    Read the article

  • final fields and thread-safety

    - by pcjuzer
    Should it be all fields, including super-fields, of a purposively immutable java class 'final' in order to be thread-safe or is it enough to have no modifier methods? Suppose I have a POJO with non-final fields where all fields are type of some immutable class. This POJO has getters-setters, and a constructor wich sets some initial value. If I extend this POJO with knocking out modifier methods, thus making it immutable, will extension class be thread-safe?

    Read the article

  • Undefined method `add' on a cucumber step that usually works.

    - by Josiah Kiehl
    I have a path defined: when /the admin home\s?page/ "/admin/" I have scenario that is passing: Scenario: Let admins see the admin homepage Given "pojo" is logged in And "pojo" is an "admin" And I am on the admin home page Then I should see "Hi there." And I have a scenario that is failing: Scenario: Review flagged photo Given "pojo" is logged in And "pojo" is an "admin" ...bunch of steps that create stuff in the database... And I am on the admin home page Then ... the rest of the steps The step that fails in the second one is "And I am on the admin home page" which passes just fine in the first scenario. Here's the error I get: And I am on the admin home page # features/step_definitions/web_steps.rb:18 undefined method `add' for {}:Hash (NoMethodError) ./app/controllers/admin_controller.rb:13:in `index' ./app/controllers/admin_controller.rb:11:in `each' ./app/controllers/admin_controller.rb:11:in `index' /usr/lib/ruby/1.8/benchmark.rb:308:in `realtime' ./features/step_definitions/web_steps.rb:19:in `/^(?:|I )am on (.+)$/' features/admin.feature:52:in `And I am on the admin home page' This is very odd... why would it be fine in the first case, and not in the second where the only difference are a bunch of steps that create records in the db? [edit] Here's the add stuff to database step: Given /^there is a "([^\"]*)" with the following:$/ do |model, table| model.constantize.create!(table.rows_hash) end

    Read the article

  • jQuery Form plugin - no data from file upload?

    - by pojo
    I've been struggling a bit with the jQuery Form plugin. I want to create a file upload form that posts the data (JSON, from the chosen file) into a REST service exposed by a servlet. The URL for the POST is calculated from what the user chooses in a SELECT dropdown. When the upload is complete, I want to notify the user immediately, AJAX-style. The problem is that the POST header has a Content-Length of 0 and contains no data. I would appreciate any help! <html> <head> <script type="text/javascript" src="js/jquery-1.4.2.min.js">/* ppp */</script> <script type="text/javascript" src="js/jquery.form.js">/* ppp */</script> <script type="text/javascript"> function cb_beforesubmit (arr, $form, options) { // This should override the form's action attribute options.url = "/rest/services/" + $('#selectedaction')[0].value; return true; } function cb_success (rt, st, xhr, wf) { $('#response').html(rt + '<br>' + st + '<br>' + xhr); } $(document).ready(function () { var options = { beforeSubmit: cb_beforesubmit, success: cb_success, dataType: 'json', contentType: 'application/json', method: 'POST', }; $('#myform').ajaxForm(options); $.getJSON('/rest/services', function (data, ts) { for (var property in data) { if (typeof property == 'string') { $('#selectedaction').append('<option>' + property + '</option>'); } } }); }); </script> </head> <body> <form id="myform" action="/rest/services/foo1" method="POST" enctype="multipart/form-data"> <!-- The form does not seem to submit at all if I don't set action to a default value? !--> <select id="selectedaction"> <script type="text/javascript"> </script> </select> <input type="file" value="Choose"/> <input type="submit" value="Submit" /> </form> <div id="response"> </div> </body> </html>

    Read the article

  • Speed up compilation with mockito on Android

    - by pbreault
    I am currently developing an android app in eclipse using: One project for the app One project for the tests (Instrumentation and Pojo tests) In the test project, I am importing the mockito library for standard POJO testing. However, when I import the library, the compilation time skyrockets from 1 second to about 30 seconds in eclipse. The cause seems to be that the whole library is converted each time. So basically, each time a make a modification that I want to test, I have to wait 30 seconds. The only workarounds that I have found so far would be: Disable "Build Automatically" Create a project that includes only pojo tests and put mockito only there. Use another library that compiles faster (e.g. easymock) Any other suggestion?

    Read the article

  • which toString() method can be used performance wise??

    - by Mrityunjay
    hi, I am working on one project for performance enhancement. I had one doubt, while we are during a process, we tend to trace the current state of the DTO and entity used. So, for this we have included toString() method in all POJOs for the same. I have now implemented toString() in three different ways which are following :- public String toString() { return "POJO :" + this.class.getName() + " RollNo :" + this.rollNo + " Name :" + this.name; } public String toString() { StringBuffer buff = new StringBuffer("POJO :").append(this.class.getName()).append(" RollNo :").append(this.rollNo).append(" Name :").append(this.name); return buff.toString(); } public String toString() { StringBuilder builder = new StringBuilder("POJO :").append(this.class.getName()).append(" RollNo :").append(this.rollNo).append(" Name :").append(this.name); return builder .toString(); } can anyone please help me to find out which one is best and should be used for enhancing performance.

    Read the article

  • Looking for design patterns to isolate framework layers from each other

    - by T Reddy
    Hi, I'm wondering if anyone has any experience in "isolating" framework objects from each other (Spring, Hibernate, Struts). I'm beginning to see design "problems" where an object from one framework gets used in another object from a different framework. My fear is we're creating tightly coupled objects. For instance, I have an application where we have a DynaActionForm with several attributes...one of which is a POJO generated by the Hibernate Tools. This POJO gets used everywhere...the JSP populates data to it, the Struts Action sends it down to a Service Layer, the DAO will persist it...ack! Now, imagine that someone decides to do a little refactoring on that POJO...so that means the JSP, Action, Service, DAO all needs to be updated...which is kind of painful...There has got to be a better way?! There's a book called Core J2EE Patterns: Best Practices and Design Strategies (2nd Edition)...is this worth a look? I don't believe it touches on any specific frameworks, but it looks like it might give some insight on how to properly layer the application... Thanks!

    Read the article

  • Java???????·????????Java EE????JAX-RS 2.0??????Java Developers Workshop 2012 Summer????

    - by ???02
    ???Java??????????????????1?????“GlassFish Guy”??????????????·????????????·????????????8???????Java Developers Workshop 2012 Summer???????????????Java EE????2??????????????????????????????????(???) Java EE??????“????·?????”????? ??????·?????????Java????????????·???? Java??????????????????????????????Java??????????Java????????·????????????????????????????????Java????????Java EE 7?JAX-RS?????????????????? 1?????????Java EE 7 and HTML5: Developing for the Cloud????????Java EE??????????????·?????????????????????????????????? Java EE?????????2009?10?????????Java EE 6??????????????????????????4,000????????????????17?????????·????Java EE 6??????????????Java EE 6?????????????????????Java EE 6??????10??????? ?????????????????WAR???????????EJB??? ????Java EE???EJB????·???????????????????????????·???????(DD)?????????????????????Java EE 6????????????EJB?“?????”?????????POJO????????????????EJB????????????????????POJO?WAR??????????????????????DD???????????????????????????????????????(????) ??1??????????????????CDI(Context Dependency Injection)????DI????Java EE 5??????????????????????????????????Java EE 6?CDI???????????·?????????????DI???????????????????Spring Framework??????????????????????????Java EE???DI??????????????????????? ????????????Java EE????????????????????????????Amazon Web Services?Windows Azure????IaaS?Google App Engine????PaaS?Salesforce.com????SaaS?????????????????????·?????????????????????????????????????????????????????????????? ????????Java EE???????????????????????????????Java EE?????????????????·????????????Java EE??????????????????????????????????????????·?????????????? ??????????????????Java EE 7??????????????Java EE 8??????·??????????????????????????HTML5??3???????????????????????????????????????????????????????????????? ?????Java EE???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? ?????Cloud Application Service(??)??????????????????????????????????????????????????????????????????????????????? ???HTML5??????“Web??????·??????”????JSON?WebSockets??????????????Java EE???????????????Web????????????????????????WebSocket???????????????????????·?????????????WebSocket?????Java EE????????????????????????????? ???Java EE 7????????API????????????????????? ??????????????????·?????????????????????·????????????????????????????5??API??Java EE 7??????????????????????????????????????????????????????????????????????????????????????????????????????????????????(????)???? Java EE 7?????????????????API????????????????????????????2013??2??????????????????????????????????????????????????????????????????Web???(http://javaee-spec.java.net/)???????????????????????????????? ??????????Project Avatar???????????Project Avatar??????????Java????????????????????????????Java????????????HTML5???????????????????????????HTML?Java???????????????????????Java EE???????????????????????????????? JAX-RS 2.0?Java??????????????????? ???????2?????????JAX-RS 2.0: RESTful Java on Steroids???Java????RESTful?????????????API???JAX-RS?????Java EE 7???????JAX-RS 2.0???????????????????????????????? ?????????“RESTful”???????????????????? ????????????????????????????? ?????????????? ???????????????? ??????????????(??)??? ????????????????????(?????????????????) ????Java EE????????API?????????????JAX-RS 1.0??JAX-RS 1.0???POJO????API???HTTP??????????????????????????????????????????????? ????????????JAX-RS 2.0???????????8??????????/???????????? ?Client API ?Client-side and Server-side Asynchronous ?Filters and Interceptors ?Improved Connection Negotiation ?Validation ?Hypermedia ?Alignment with JSR 330 ?Model-View-Controller JAX-RS 2.0??????????????·????????????????????Model-View-Controller?????????????????????Model-View-Controller?????????JSF????MVC???????????????JAX-RS???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? ???Client API???????????????HTTP??????·????????????????????????API???????????????JAX-RS 2.0?Client API???JAX-RS?????API??????????????Java EE?????????????REST??????????????????? ?Filters&Interceptors????????????????????????JAX-RS??????????????????JAX-RS 1.0???????????JAX-RS 2.0??????????????????????? ?Asynchronus??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? ?Connect Negotiation???Validation???????????????????????Validation????????????????Bean Validation?????JAX-RS?????????????????????????? ?Hypermedia???????????????????Web???????????????????HATEOAS(Hypermedia As The Engine Of App State)?????JAX-RS????????????????????????????????Asynchronus???????????????????????????? JAX-RS 2.0???????????JSR 330:Dependency Injection for Java???????????????????Client API??????????????????????????????????????JAX-RS 2.0??????????????????????Web???????????·??????????(http://jcp.org/en/jsr/detail?id=339)????????????????????????????????????????

    Read the article

  • Use a single freemarker template to display tables of arbitrary pojos

    - by Kevin Pauli
    Attention advanced Freemarker gurus: I want to use a single freemarker template to be able to output tables of arbitrary pojos, with the columns to display defined separately than the data. The problem is that I can't figure out how to get a handle to a function on a pojo at runtime, and then have freemarker invoke that function (lambda style). From skimming the docs it seems that Freemarker supports functional programming, but I can't seem to forumulate the proper incantation. I whipped up a simplistic concrete example. Let's say I have two lists: a list of people with a firstName and lastName, and a list of cars with a make and model. would like to output these two tables: <table> <tr> <th>firstName</th> <th>lastName</th> </tr> <tr> <td>Joe</td> <td>Blow</d> </tr> <tr> <td>Mary</td> <td>Jane</d> </tr> </table> and <table> <tr> <th>make</th> <th>model</th> </tr> <tr> <td>Toyota</td> <td>Tundra</d> </tr> <tr> <td>Honda</td> <td>Odyssey</d> </tr> </table> But I want to use the same template, since this is part of a framework that has to deal with dozens of different pojo types. Given the following code: public class FreemarkerTest { public static class Table { private final List<Column> columns = new ArrayList<Column>(); public Table(Column[] columns) { this.columns.addAll(Arrays.asList(columns)); } public List<Column> getColumns() { return columns; } } public static class Column { private final String name; public Column(String name) { this.name = name; } public String getName() { return name; } } public static class Person { private final String firstName; private final String lastName; public Person(String firstName, String lastName) { this.firstName = firstName; this.lastName = lastName; } public String getFirstName() { return firstName; } public String getLastName() { return lastName; } } public static class Car { String make; String model; public Car(String make, String model) { this.make = make; this.model = model; } public String getMake() { return make; } public String getModel() { return model; } } public static void main(String[] args) throws Exception { final Table personTableDefinition = new Table(new Column[] { new Column("firstName"), new Column("lastName") }); final List<Person> people = Arrays.asList(new Person[] { new Person("Joe", "Blow"), new Person("Mary", "Jane") }); final Table carTable = new Table(new Column[] { new Column("make"), new Column("model") }); final List<Car> cars = Arrays.asList(new Car[] { new Car("Toyota", "Tundra"), new Car("Honda", "Odyssey") }); final Configuration cfg = new Configuration(); cfg.setClassForTemplateLoading(FreemarkerTest.class, ""); cfg.setObjectWrapper(new DefaultObjectWrapper()); final Template template = cfg.getTemplate("test.ftl"); process(template, personTableDefinition, people); process(template, carTable, cars); } private static void process(Template template, Table tableDefinition, List<? extends Object> data) throws Exception { final Map<String, Object> dataMap = new HashMap<String, Object>(); dataMap.put("tableDefinition", tableDefinition); dataMap.put("data", data); final Writer out = new OutputStreamWriter(System.out); template.process(dataMap, out); out.flush(); } } All the above is a given for this problem. So here is the template I have been hacking on. Note the comment where I am having trouble. <table> <tr> <#list tableDefinition.columns as col> <th>${col.name}</th> </#list> </tr> <#list data as pojo> <tr> <#list tableDefinition.columns as col> <td><#-- what goes here? --></td> </#list> </tr> </#list> </table> So col.name has the name of the property I want to access from the pojo. I have tried a few things, such as pojo.col.name and <#assign property = col.name/> ${pojo.property} but of course these don't work, I just included them to help convey my intent. I am looking for a way to get a handle to a function and have freemarker invoke it, or perhaps some kind of "evaluate" feature that can take an arbitrary expression as a string and evaluate it at runtime.

    Read the article

  • Good design of mapping Java Domain objects to Tables (using Hibernate)

    - by M. McKenzie
    Hey guys, I have a question that is more in the realm of design, than implementation. I'm also happy for anyone to point out resources for the answer and I'll gladly, research for myself. Highly simplified Java and SQL: Say I have a business domain POJO called 'Picture' with three attributes. class Picture int idPicture String fileName long size Say I have another business domain POJO called "Item" with 3 attributes Class Item int idItem String itemName ArrayList itemPictures These would be a normal simple relationship. You could say that 'Picture' object, will never exist outside an 'Item' object. Assume a picture belongs only to a specific item, but that an item can have multiple pictures Now - using good database design (3rd Normal Form), we know that we should put items and pictures in their own tables. Here is what I assume would be correct. table Item int idItem (primary key) String itemName table Picture int idPicture (primary key) varchar(45) fileName long size int idItem (foreign key) Here is my question: If you are making Hibernate mapping files for these objects. In the data design, your Picture table needs a column to refer to the Item, so that a foreign key relation can be maintained. However,in your business domain objects - your Picture does not hold a reference/attribute to the idItem - and does not need to know it. A java Picture instance is always instantiated inside an Item instance. If you want to know the Item that the Picture belongs to you are already in the correct scope. Call myItem.getIdItem() and myItem.getItemPictures(),and you have the two pieces of information you need. I know that Hibernate tools have a generator that can auto make your POJO's from looking at your database. My problem stems from the fact that I planned out the data design for this experiment/project first. Then when I went to make the domain java objects, I realized that good design dictated that the objects hold other objects in a nested way. This is obviously different from the way that a database schema is - where all objects(tables) are flat and hold no other complex types within them. What is a good way to reconcile this? Would you: (A) Make the hibernate mapping files so that Picture.hbm.xml has a mapping to the POJO parent's idItem Field (if it's even possible) (B) Add an int attribute in the Picture class to refer to the idItem and set it at instantiation, thus simplifying the hbm.xml mapping file by having all table fields as local attributes in the class (C) Fix the database design because it is wrong, dork. I'd truly appreciate any feedback

    Read the article

  • The type of field isn't supported by declared persistence strategy "OneToMany"

    - by Robert
    We are new to JPA and trying to setup a very simple one to many relationship where a pojo called Message can have a list of integer group id's defined by a join table called GROUP_ASSOC. Here is the DDL: CREATE TABLE "APP"."MESSAGE" ( "MESSAGE_ID" INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1) ); ALTER TABLE "APP"."MESSAGE" ADD CONSTRAINT "MESSAGE_PK" PRIMARY KEY ("MESSAGE_ID"); CREATE TABLE "APP"."GROUP_ASSOC" ( "GROUP_ID" INTEGER NOT NULL, "MESSAGE_ID" INTEGER NOT NULL ); ALTER TABLE "APP"."GROUP_ASSOC" ADD CONSTRAINT "GROUP_ASSOC_PK" PRIMARY KEY ("MESSAGE_ID", "GROUP_ID"); ALTER TABLE "APP"."GROUP_ASSOC" ADD CONSTRAINT "GROUP_ASSOC_FK" FOREIGN KEY ("MESSAGE_ID") REFERENCES "APP"."MESSAGE" ("MESSAGE_ID"); Here is the pojo: @Entity @Table(name = "MESSAGE") public class Message { @Id @Column(name = "MESSAGE_ID") @GeneratedValue(strategy = GenerationType.IDENTITY) private int messageId; @OneToMany(fetch=FetchType.LAZY, cascade=CascadeType.PERSIST) private List groupIds; public int getMessageId() { return messageId; } public void setMessageId(int messageId) { this.messageId = messageId; } public List getGroupIds() { return groupIds; } public void setGroupIds(List groupIds) { this.groupIds = groupIds; } } When we try to execute the following test code we get <openjpa-1.2.3-SNAPSHOT-r422266:907835 fatal user error> org.apache.openjpa.util.MetaDataException: The type of field "pojo.Message.groupIds" isn't supported by declared persistence strategy "OneToMany". Please choose a different strategy. Message msg = new Message(); List groups = new ArrayList(); groups.add(101); groups.add(102); EntityManager em = Persistence.createEntityManagerFactory("TestDBWeb").createEntityManager(); em.getTransaction().begin(); em.persist(msg); em.getTransaction().commit(); Help!

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9  | Next Page >