2014年03月

Hibernate Entity mapping when Foreign key is part of the composite primary key?

I have a Table with a composite PK : Customer
I have a View with no PK : Purchase





To bind my Entity, Hibernate forces me to declare a PK.
So I've created a composite PK For Purchase.



Puchase:



@Entity
@Table(name = "PURCHASE")
public class Purchase {

@EmbeddedId
private PurchasePK id;
}


PuchasePK:



@Embeddable
public class PurchasePK {

@Column(name = "CUST_LASTNAME")
private String custLastname;

@Column(name = "OBJ_NAME")
private Long objectName;
}


Customer is straight forward :



@Entity
@Table(name = "CUSTOMER")
public class Customer {

@EmbeddedId
private CustomerPK id;
}


With its composite PK:



@Embeddable
public class CustomerPK {

@Column(name = "CUST_LASTNAME")
private String custLastname;

@Column(name = "CUST_NAME")
private Long custName;
}


Now I want to create a OneToMany attribut in Customer by matching both table CUST_NAME.



@OneToMany
private List<Purchase> listPurchases;


How can i do that?



I've searched quite a bit and it always comes down to not being able to do FK on 1 column if the PK has 2 columns ...



PS: I'm using JPA 1, so I don't have access to @MapsId.



PS2: My real model is not about Customer & purchase and the attributs used for the PKs are not varchar but Long.



Answers

Answering directly to your question - I think you cannot do that.
I would suggest to rethink this model by introducing CUSTOMER_ID field since first+last name quite often are not unique from practice. Moreover joining only by last name will give you mix of purchases since there could be "Mike Smith", "John Smith" as a customers. Having numeric ID will solve all your problems I suppose.





PaperScript : Why for non pre-defined shapes, it is need to be selected for it to display?

I am new to PaperScript and I am trying to make hexagon using it. I have used following two codes. One works and one doesn't. I am not able to figure out the reason behind this behaviour:



Working code:



var triangle = new Path.RegularPolygon(new Point(80, 70), 3, 50);
triangle.fillColor = '#e9e9ff';
triangle.selected = true;


Not working code:



var triangle = new Path.RegularPolygon(new Point(80, 70), 3, 50);
triangle.fillColor = '#e9e9ff';


Why there is need to select the path for it to display (in case of not pre defined shapes) but for pre-defined shapes (like Circle or Rectangle) it is not needed?





How do I define only scheduler attribues in the deploymnet descriptor, not the whole bean?

I have the following bean:



@Stateless
public class NewSessionBean {

public void myJob() {
System.out.println("RUN");
}

}


and I would like to have myJob running every 10 seconds, so I have this Deployment descriptor:



<ejb-jar xmlns = "http://java.sun.com/xml/ns/javaee"
version = "3.1"
xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation = "http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/ejb-jar_3_1.xsd">
<enterprise-beans>
<session>
<ejb-name>NewSessionBean</ejb-name>
<ejb-class>org.test.NewSessionBean</ejb-class>
<session-type>Stateless</session-type>
<timer>
<schedule>
<second>*/10</second>
<minute>*</minute>
<hour>*</hour>
<month>*</month>
<year>*</year>
</schedule>
<timeout-method>
<method-name>myJob</method-name>
</timeout-method>
</timer>
</session>
</enterprise-beans>
</ejb-jar>


And it works.



But I would like to declare only the timer in my deployment descriptor, not the whole bean so I can declare everything using annotations and parametrize the schedule.



If I remove the ejb-class or session-type my application won't load because the DD is missing this information.



Is there anyway that I can override the information for the scheduler only?



Edit: I would like to move set the parameters on the @schedule annotation to the deployment descriptor so I can change its values without needing to recompile/redeploy anything





How can I delete a chat message with Emberfire?

I've created an action to add messages to my firebase, but can't seem to figure out how to remove a specific message. Here is my new message controller so far:



import Ember from 'ember';

export default Ember.Controller.extend({
//define actions here
actions: {
addMessage: function() {
//createRecord creates new instance of message model
var newMessage = this.store.createRecord('message', {
//this gets the info from the form fields with this value
name: this.get('name'),
body: this.get('body')
});
//this saves the data to store and firebase
newMessage.save();
//this resets the fields to be blank again
this.setProperties({
name: '',
body: ''
});
}
}
});


and this is my message controller with the remove action



import Ember from 'ember';

export default Ember.Controller.extend({
actions: {
deleteMessage: function(id) {
var msg = this.store.find('message', id, {
//this gets the info from the form fields with this value
name: this.get('name'),
body: this.get('body')
});
//this deletes the data to store and firebase
msg.remove();
}
}
});


and here's my template



<div class="new-msg-link">
{{#link-to 'messages.new'}}Add New Message{{/link-to}}
</div>

{{outlet}}

{{#each message in model}}
<div class="each-msg">
{{message.name}}: {{message.body}}
<button {{action 'deleteMessage'}}>Delete</button>
</div>
{{/each}}


I'm not sure how to pass the id parameter in my action correctly and how to get it from firebase correctly. Any suggestions would be great! thanks





How to recognise a song by listening using Echonest for iOS?

I want to implement a functionality similar to the one integrated in Shazam app. I want my app by pressing to a button to "listen" for a song and after some time to "guess" the song or give some predictions using Echonest api for iOS. I was searching the web and so far I've learned the I need to send the fingerprint to the Echonest server and give me response with the song info. But somewhere I've read that that functionality will be no more available. Also tried to upload the whole mp3 file to their server and the response is always an empty one. Does anyone has experience with this issue and tell me where I'm wrong?
I've used echoprint but no success.





↑このページのトップヘ